qemacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemacs-devel] Changes to qemacs/cutils.c


From: Charlie Gordon
Subject: [Qemacs-devel] Changes to qemacs/cutils.c
Date: Tue, 10 May 2005 14:53:04 -0400

Index: qemacs/cutils.c
diff -u qemacs/cutils.c:1.2 qemacs/cutils.c:1.3
--- qemacs/cutils.c:1.2 Tue Nov 30 10:18:00 2004
+++ qemacs/cutils.c     Tue May 10 18:53:04 2005
@@ -93,7 +93,7 @@
     if (buf_size <= 0)
         return;
 
-    for(;;) {
+    for (;;) {
         c = *str++;
         if (c == 0 || q >= buf + buf_size - 1)
             break;
@@ -112,6 +112,28 @@
     return buf;
 }
 
+/* copy the n first char of a string and truncate it. */
+char *pstrncpy(char *buf, int buf_size, const char *s, int len)
+{
+    char *q;
+    int c;
+
+    if (buf_size > 0) {
+        q = buf;
+        if (len >= buf_size)
+            len = buf_size - 1;
+        while (len > 0) {
+            c = *s++;
+            if (c == '\0')
+                break;
+            *q++ = c;
+            len--;
+        }
+        *q = '\0';
+    }
+    return buf;
+}
+
 #endif
 
 /**




reply via email to

[Prev in Thread] Current Thread [Next in Thread]