summaryrefslogtreecommitdiffstats
path: root/hw4/l4basic/l4str.c
diff options
context:
space:
mode:
authorLAN-TW <lantw44@gmail.com>2014-01-12 16:42:19 +0800
committerLAN-TW <lantw44@gmail.com>2014-01-12 16:42:19 +0800
commit0c1dfc4fcbf9764633aa6cb1798e63d55af66752 (patch)
tree73eb50e8924c41cc2721c50aa731bec5ca03c196 /hw4/l4basic/l4str.c
parent57ab8916608d8b319a1b522bdb2e549ebcac1072 (diff)
downloadsp2013-0c1dfc4fcbf9764633aa6cb1798e63d55af66752.tar
sp2013-0c1dfc4fcbf9764633aa6cb1798e63d55af66752.tar.gz
sp2013-0c1dfc4fcbf9764633aa6cb1798e63d55af66752.tar.bz2
sp2013-0c1dfc4fcbf9764633aa6cb1798e63d55af66752.tar.lz
sp2013-0c1dfc4fcbf9764633aa6cb1798e63d55af66752.tar.xz
sp2013-0c1dfc4fcbf9764633aa6cb1798e63d55af66752.tar.zst
sp2013-0c1dfc4fcbf9764633aa6cb1798e63d55af66752.zip
HW4: 準備 build system
Diffstat (limited to 'hw4/l4basic/l4str.c')
-rw-r--r--hw4/l4basic/l4str.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/hw4/l4basic/l4str.c b/hw4/l4basic/l4str.c
new file mode 100644
index 0000000..fa1d31b
--- /dev/null
+++ b/hw4/l4basic/l4str.c
@@ -0,0 +1,44 @@
+#include "memwrap.h"
+/* This file is modified by autogen.sh */
+/* vim: set sw=4 ts=4 sts=4 et: */
+
+#include "l4str.h"
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+bool lbs_str_has_suffix (const char* str, const char* suffix) {
+ size_t len = strlen (str);
+ size_t suflen = strlen (suffix);
+ int i, j;
+ for (i = len - 1, j = suflen - 1; i >= 0 && j >= 0; i--, j--) {
+ if (str[i] != suffix[j]) {
+ return false;
+ }
+ }
+ if (i < 0 && j >= 0) {
+ return false;
+ }
+ return true;
+}
+
+char* lbs_str_printf (const char* format, ...) {
+ va_list ap;
+ char* newstr;
+ int len;
+
+ va_start (ap, format);
+ len = vsnprintf (NULL, 0, format, ap) + 1;
+ va_end (ap);
+
+ newstr = xmalloc (len);
+
+ va_start (ap, format);
+ vsnprintf (newstr, len, format, ap);
+ va_end (ap);
+
+ return newstr;
+}
+