diff options
author | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:31:57 +0000 |
---|---|---|
committer | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:31:57 +0000 |
commit | 09e967c2d732783b2579e4e120cd9b608404cb00 (patch) | |
tree | 8d2783a6a7e33608c6012efd6a88b8f5694df81d /mdk-stage1/dietlibc/libshell | |
parent | 18fcff49d3c836697d3b75a3d01d31c700e69974 (diff) | |
download | drakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar drakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar.gz drakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar.bz2 drakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar.xz drakx-09e967c2d732783b2579e4e120cd9b608404cb00.zip |
Merge from R9_0-AMD64, most notably:
- AMD64 support to insmod-busybox, minilibc, et al.
- Sync with insmod-modutils 2.4.19 something but everyone should use
dietlibc nowadays
- Factor out compilation and prefix with $(DIET) for dietlibc builds
- 64-bit & varargs fixes
Diffstat (limited to 'mdk-stage1/dietlibc/libshell')
-rw-r--r-- | mdk-stage1/dietlibc/libshell/fnmatch.c | 34 | ||||
-rw-r--r-- | mdk-stage1/dietlibc/libshell/glob.c | 84 | ||||
-rw-r--r-- | mdk-stage1/dietlibc/libshell/realpath.c | 18 |
3 files changed, 73 insertions, 63 deletions
diff --git a/mdk-stage1/dietlibc/libshell/fnmatch.c b/mdk-stage1/dietlibc/libshell/fnmatch.c index 4e7664510..ef43735f6 100644 --- a/mdk-stage1/dietlibc/libshell/fnmatch.c +++ b/mdk-stage1/dietlibc/libshell/fnmatch.c @@ -1,5 +1,6 @@ #include <ctype.h> #include <fnmatch.h> +#include <string.h> #define NOTFIRST 128 @@ -11,6 +12,7 @@ static int match(char c,char d,int flags) { } int fnmatch(const char *pattern, const char *string, int flags) { + /*printf("fnmatch(\"%s\",\"%s\")\n",pattern,string);*/ if (*string==0) { while (*pattern=='*') ++pattern; return (!!*pattern); @@ -18,31 +20,36 @@ int fnmatch(const char *pattern, const char *string, int flags) { if (*string=='.' && *pattern!='.' && (flags&FNM_PERIOD)) { /* don't match if FNM_PERIOD and this is the first char */ if ((flags&FNM_PERIOD) && (!(flags&NOTFIRST))) - return 1; + return FNM_NOMATCH; /* don't match if FNM_PERIOD and FNM_FILE_NAME and previous was '/' */ if ((flags&(FNM_FILE_NAME|FNM_PERIOD)) && string[-1]=='/') - return 1; + return FNM_NOMATCH; } flags|=NOTFIRST; switch (*pattern) { case '[': - ++pattern; - while (*pattern && *pattern!=']') { - if (flags&FNM_PATHNAME || *string!='/') { + { + int neg=0; + ++pattern; + if (*string=='/' && flags&FNM_PATHNAME) return FNM_NOMATCH; + if (*pattern=='^') { neg=1; ++pattern; } + while (*pattern && *pattern!=']') { int res=0; if (pattern[1]=='-') { if (*string>=*pattern && *string<=pattern[2]) res=1; if (flags&FNM_CASEFOLD) { if (tolower(*string)>=tolower(*pattern) && tolower(*string)<=tolower(pattern[2])) res=1; } - } else + pattern+=3; + } else { res=match(*pattern,*string,flags); - if (res) { + ++pattern; + } + if (res ^ neg) { while (*pattern && *pattern!=']') ++pattern; return fnmatch(pattern+1,string+1,flags); } } - ++pattern; } break; case '\\': @@ -55,12 +62,9 @@ int fnmatch(const char *pattern, const char *string, int flags) { } break; case '*': - if (!pattern[1] || fnmatch(pattern+1,string,flags)==0) - return 0; - else - if (*string!='/') - return fnmatch(pattern,string+1,flags); - break; + if ((*string=='/' && flags&FNM_PATHNAME) || fnmatch(pattern,string+1,flags)) + return fnmatch(pattern+1,string,flags); + return 0; case 0: if (*string==0 || (*string=='/' && (flags&FNM_LEADING_DIR))) return 0; @@ -70,5 +74,5 @@ int fnmatch(const char *pattern, const char *string, int flags) { return fnmatch(pattern+1,string+1,flags); break; } - return 1; + return FNM_NOMATCH; } diff --git a/mdk-stage1/dietlibc/libshell/glob.c b/mdk-stage1/dietlibc/libshell/glob.c index 34d09d87a..def55f8dc 100644 --- a/mdk-stage1/dietlibc/libshell/glob.c +++ b/mdk-stage1/dietlibc/libshell/glob.c @@ -24,6 +24,7 @@ #include <fnmatch.h> #include <dirent.h> #include <pwd.h> +#include "dietfeatures.h" #include <glob.h> @@ -38,7 +39,7 @@ static int cmp_func(const void * a, const void * b) return 1; if (s2 == NULL) return -1; - return strcmp(s1, s2); + return strcoll(s1, s2); } @@ -47,6 +48,38 @@ static int cmp_func(const void * a, const void * b) The GLOB_NOSORT bit in FLAGS is ignored. No sorting is ever done. The GLOB_APPEND flag is assumed to be set (always appends). Prepends DIRECTORY in constructed PGLOB. */ +static void close_dir_keep_errno(DIR* dp) { + int save = errno; + if (dp) + closedir (dp); + errno=save; +} + +static int add_entry(const char* name,glob_t *pglob,int* nfound) { + pglob->gl_pathv = (char **) realloc(pglob->gl_pathv, + (pglob->gl_pathc + pglob->gl_offs + 2) + * sizeof (char *)); + if (pglob->gl_pathv == NULL) + return 1; + pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc] = strdup(name); + pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc + 1] = NULL; + pglob->gl_pathc++; + (*nfound)++; + return 0; +} + +static void build_fullname(char * fullname, const char * directory, const char * filename) { + char *dest=fullname; + if (directory[0]=='/' && !directory[1]) { + *dest='/'; ++dest; + } else if (directory[0]!='.' || directory[1]) { + strcpy(dest,directory); + dest=strchr(dest,0); + *dest='/'; ++dest; + } + strcpy(dest,filename); +} + static int glob_in_dir(const char *pattern, const char *directory, int flags, int errfunc(const char * epath, int eerrno), glob_t *pglob) @@ -57,33 +90,6 @@ static int glob_in_dir(const char *pattern, const char *directory, int flags, int i; char * ptr; - void close_dir_keep_errno(void) { - int save = errno; - if (dp) - closedir (dp); - __set_errno(save); - } - int add_entry(const char * name) { - pglob->gl_pathv = (char **) realloc(pglob->gl_pathv, - (pglob->gl_pathc + pglob->gl_offs + 2) - * sizeof (char *)); - if (pglob->gl_pathv == NULL) - return 1; - pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc] = strdup(name); - pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc + 1] = NULL; - pglob->gl_pathc++; - nfound++; - return 0; - } - void build_fullname(char * fullname, int fullnamesize, const char * directory, const char * filename) { - if (!strcmp(directory, "/")) - snprintf(fullname, fullnamesize, "/%s", filename); - else if (!strcmp(directory, ".")) - snprintf(fullname, fullnamesize, "%s", filename); - else - snprintf(fullname, fullnamesize, "%s/%s", directory, filename); - } - if (!dp) { if (errno != ENOTDIR && ((errfunc != NULL && (*errfunc) (directory, errno)) @@ -96,19 +102,19 @@ static int glob_in_dir(const char *pattern, const char *directory, int flags, while ((ep = readdir(dp))) { i = strlen(directory) + strlen(ep->d_name) + 2; ptr = (char *) alloca(i); - build_fullname(ptr, i, directory, ep->d_name); + build_fullname(ptr, directory, ep->d_name); if (flags & GLOB_ONLYDIR) { struct stat statr; if (stat(ptr, &statr) || !S_ISDIR(statr.st_mode)) continue; } if (fnmatch(pattern, ep->d_name, fnm_flags) == 0) - if (add_entry(ptr)) + if (add_entry(ptr,pglob,&nfound)) goto memory_error; } } - close_dir_keep_errno(); + close_dir_keep_errno(dp); if (nfound != 0) pglob->gl_flags = flags; @@ -116,8 +122,8 @@ static int glob_in_dir(const char *pattern, const char *directory, int flags, /* nfound == 0 */ i = strlen(directory) + strlen(pattern) + 2; ptr = (char *) alloca(i); - build_fullname(ptr, i, directory, pattern); - if (add_entry(ptr)) + build_fullname(ptr, directory, pattern); + if (add_entry(ptr,pglob,&nfound)) goto memory_error; } @@ -127,7 +133,7 @@ static int glob_in_dir(const char *pattern, const char *directory, int flags, /* We're in trouble since we can't free the already allocated memory. [allocated from strdup(filame)] * Well, after all, when malloc returns NULL we're already in a bad mood, and no doubt the * program will manage to segfault by itself very soon :-). */ - close_dir_keep_errno(); + close_dir_keep_errno(dp); return GLOB_NOSPACE; } @@ -146,7 +152,7 @@ int glob(const char *pattern, int flags, int errfunc(const char * epath, int eer char * ptr, * ptr2; if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0) { - __set_errno (EINVAL); + errno=EINVAL; return -1; } @@ -196,10 +202,10 @@ int glob(const char *pattern, int flags, int errfunc(const char * epath, int eer if (filename == NULL) { /* We have no '/' in the pattern */ filename = pattern_; - dirname = "."; + dirname = (char*)"."; } else if (filename == pattern_) { /* "/pattern". */ - dirname = "/"; + dirname = (char*)"/"; filename++; } else { dirname = pattern_; @@ -293,13 +299,13 @@ int glob(const char *pattern, int flags, int errfunc(const char * epath, int eer } /* okay now we add the new entry */ - k = strlen(dirs.gl_pathv[i]) + 1 + strlen(filename) + 1; + k = strlen(dirs.gl_pathv[i]) + strlen(filename) + 2; if ((pglob->gl_pathv[j] = malloc(k)) == NULL) { globfree(&dirs); globfree(pglob); return GLOB_NOSPACE; } - snprintf(pglob->gl_pathv[j], k, "%s/%s", dirs.gl_pathv[i], filename); + build_fullname(pglob->gl_pathv[j], dirs.gl_pathv[i], filename); pglob->gl_pathc++; pglob->gl_pathv[j+1] = NULL; } diff --git a/mdk-stage1/dietlibc/libshell/realpath.c b/mdk-stage1/dietlibc/libshell/realpath.c index 1377018e5..9aee2c585 100644 --- a/mdk-stage1/dietlibc/libshell/realpath.c +++ b/mdk-stage1/dietlibc/libshell/realpath.c @@ -5,21 +5,21 @@ #include <string.h> #include "dietfeatures.h" -char *realpath(const char *path, char *resolved_path) { +char* realpath(const char *path, char *resolved_path) { int fd=open(".",O_RDONLY); - char *tmp=""; + char* tmp=(char*)""; + if (fd<0) return 0; if (chdir(path)) { -#ifdef WANT_THREAD_SAFE - if (*__errno_location()==ENOTDIR) -#else - if (errno==ENOTDIR) -#endif - { - if ((tmp=strrchr(path,'/'))) { + if (errno==ENOTDIR) { + char* match; + if ((match=strrchr(path,'/'))) { + tmp=match; memmove(resolved_path,path,tmp-path); resolved_path[tmp-path]=0; if (chdir(resolved_path)) { resolved_path=0; goto abort; } } + } else { + resolved_path=0; goto abort; } } if (!getcwd(resolved_path,PATH_MAX)) { resolved_path=0; goto abort; } |