Partially sync files.el from XEmacs 21.5 for wildcard support.
[sxemacs] / src / emodules-ng.c
index 4124dc7..6b3c851 100644 (file)
@@ -150,6 +150,7 @@ __emodng_open_append_exts(const char *filename)
        char name[nname + /*length of longest extension:*/24];
        /* note to myself: better check that length! */
        char *p = xstpncpy(name, filename, nname+1);
+       size_t remain = name + sizeof(name) - p;
 
        for (Lisp_Object ext = Vmodule_extensions;
             CONSP(ext); ext = XCDR(ext)) {
@@ -158,7 +159,7 @@ __emodng_open_append_exts(const char *filename)
                }
 
                xstrncpy(p, (const char*)XSTRING_DATA(XCAR(ext)),
-                        name + sizeof(name) - p);
+                        remain);
 
                if (__file_exists_p(name)) {
                        EMOD_DEBUG_LOADER("trying %s\n", name);
@@ -189,7 +190,7 @@ __emodng_open_prepend_paths(const char *filename)
                        char *p;
                        p = xstpncpy(name,
                                     (const char*)XSTRING_DATA(XCAR(path)),
-                                    (size_t)XSTRING_LENGTH(XCAR(path)-2));
+                                    sizeof(name)-2);
                        *p++ = '/';
                        *p = '\0';
                        xstrncpy(p, filename, name + sizeof(name) - p);
@@ -223,15 +224,17 @@ __emodng_open_prepend_paths_append_exts(const char *filename)
                         * carries the correct extension
                         * see __emodng_open_prepend_paths_append_exts for
                         * cope with all the combinations */
-                       char *p = xstpncpy(
-                               name,
+                       char *p = xstpncpy(name,
                                (const char*)XSTRING_DATA(XCAR(path)),
-                               (size_t)XSTRING_LENGTH(XCAR(path))-2);
+                               sizeof(name)-2);
+                       int remain;
                        if (*(p-1) != '/') {
                                *p++ = '/';
                                *p = '\0';
                        }
-                       p = xstpncpy(p, filename, name + sizeof(name) - p);
+                       remain = name+sizeof(name)-p;
+                       p = xstpncpy(p, filename, remain);
+                       remain = name+sizeof(name)-p;
 
                        /* append all extensions now */
                        for (Lisp_Object ext = Vmodule_extensions;
@@ -241,7 +244,7 @@ __emodng_open_prepend_paths_append_exts(const char *filename)
                                }
 
                                xstrncpy(p,(const char*)XSTRING_DATA(XCAR(ext)),
-                                        name + sizeof(name) - p);
+                                        remain);
 
                                if (__file_exists_p(name)) {
                                        EMOD_DEBUG_LOADER("trying \"%s\"\n",
@@ -845,7 +848,7 @@ _adapt_load_path(Lisp_Object sym, Lisp_Object *val,
                        if (LIKELY((STRINGP(lse)))) {
                                p = xstpncpy(p,
                                             (const char*)XSTRING_DATA(lse),
-                                            XSTRING_LENGTH(lse));
+                                            sp+sizeof(sp)-p-1);
                                *p++ = ':';
                        }
                }