diff options
author | Eric Andersen | 2001-04-09 22:48:12 +0000 |
---|---|---|
committer | Eric Andersen | 2001-04-09 22:48:12 +0000 |
commit | e5dfced23a904d08afa5dcee190c3c3d845d9f50 (patch) | |
tree | ef367ee8a9096884fb40debdc9e10af8583f9d5f /libbb | |
parent | a75e2867435faa68ea03735fe09ad298fa3e4e72 (diff) | |
download | busybox-e5dfced23a904d08afa5dcee190c3c3d845d9f50.zip busybox-e5dfced23a904d08afa5dcee190c3c3d845d9f50.tar.gz |
Apply Vladimir's latest cleanup patch.
-Erik
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/concat_path_file.c | 24 | ||||
-rw-r--r-- | libbb/libbb.h | 7 | ||||
-rw-r--r-- | libbb/print_file.c | 29 | ||||
-rw-r--r-- | libbb/process_escape_sequence.c | 73 | ||||
-rw-r--r-- | libbb/xgetcwd.c | 52 |
5 files changed, 133 insertions, 52 deletions
diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c new file mode 100644 index 0000000..d53dc0e --- /dev/null +++ b/libbb/concat_path_file.c @@ -0,0 +1,24 @@ +/* + * busybox library eXtendet funcion + * + * concatenate path and file name to new allocation buffer, + * not addition '/' if path name already have '/' + * +*/ + +#include "libbb.h" + +extern char *concat_path_file(const char *path, const char *filename) +{ + char *outbuf; + int l; + int flg_slash = 1; + + l = strlen(path); + if(l>0 && path[l-1] == '/') + flg_slash--; + l += strlen(filename); + outbuf = xmalloc(l+1+flg_slash); + sprintf(outbuf, (flg_slash ? "%s/%s" : "%s%s"), path, filename); + return outbuf; +} diff --git a/libbb/libbb.h b/libbb/libbb.h index 05f61f2..0001cac 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h @@ -131,7 +131,7 @@ extern int find_real_root_device_name(char* name); extern char *get_line_from_file(FILE *file); extern void print_file(FILE *file); extern int print_file_by_name(char *filename); -extern char process_escape_sequence(char **ptr); +extern char process_escape_sequence(const char **ptr); extern char *get_last_path_component(char *path); extern FILE *wfopen(const char *path, const char *mode); extern FILE *xfopen(const char *path, const char *mode); @@ -150,7 +150,7 @@ extern char *xstrndup (const char *s, int n); extern char * safe_strncpy(char *dst, const char *src, size_t size); struct suffix_mult { - char *suffix; + const char *suffix; int mult; }; @@ -213,4 +213,7 @@ enum { int ask_confirmation(void); int klogctl(int type, char * b, int len); +char *xgetcwd(char *cwd); +char *concat_path_file(const char *path, const char *filename); + #endif /* __LIBBB_H__ */ diff --git a/libbb/print_file.c b/libbb/print_file.c index 52a3977..b477234 100644 --- a/libbb/print_file.c +++ b/libbb/print_file.c @@ -2,9 +2,7 @@ /* * Utility routines. * - * Copyright (C) tons of folks. Tracking down who wrote what - * isn't something I'm going to worry about... If you wrote something - * here, please feel free to acknowledge your work. + * Copyright (C) 1999-2001 Erik Andersen <andersee@debian.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,13 +17,10 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Based in part on code from sash, Copyright (c) 1999 by David I. Bell - * Permission has been granted to redistribute this code under the GPL. - * */ #include <stdio.h> +#include <sys/stat.h> #include "libbb.h" @@ -41,11 +36,21 @@ extern void print_file(FILE *file) extern int print_file_by_name(char *filename) { - FILE *file; - if ((file = wfopen(filename, "r")) == NULL) - return FALSE; - print_file(file); - return TRUE; + struct stat statBuf; + int status = TRUE; + + if(is_directory(filename, TRUE, &statBuf)==TRUE) { + error_msg("%s: Is directory", filename); + status = FALSE; + } else { + FILE *f = wfopen(filename, "r"); + if(f!=NULL) + print_file(f); + else + status = FALSE; + } + + return status; } diff --git a/libbb/process_escape_sequence.c b/libbb/process_escape_sequence.c index ad2be94..67b0490 100644 --- a/libbb/process_escape_sequence.c +++ b/libbb/process_escape_sequence.c @@ -2,9 +2,8 @@ /* * Utility routines. * - * Copyright (C) tons of folks. Tracking down who wrote what - * isn't something I'm going to worry about... If you wrote something - * here, please feel free to acknowledge your work. + * Copyright (C) Manuel Nova III <mnovoa3@bellsouth.net> + * and Vladimir Oleynik <vodz@usa.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,9 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Based in part on code from sash, Copyright (c) 1999 by David I. Bell - * Permission has been granted to redistribute this code under the GPL. - * + * */ #include <stdio.h> @@ -31,45 +28,45 @@ -char process_escape_sequence(char **ptr) +char process_escape_sequence(const char **ptr) { - static const char charmap[] = { - 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0, - '\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' }; - - const char *p; - char *q; - int num_digits; - unsigned int n; + static const char charmap[] = { + 'a', 'b', 'f', 'n', 'r', 't', 'v', '\\', 0, + '\a', '\b', '\f', '\n', '\r', '\t', '\v', '\\', '\\' }; - n = 0; - q = *ptr; + const char *p; + const char *q; + int num_digits; + unsigned int n; + + n = 0; + q = *ptr; - for ( num_digits = 0 ; num_digits < 3 ; ++num_digits) { - if ((*q < '0') || (*q > '7')) { /* not a digit? */ - break; - } - n = n * 8 + (*q++ - '0'); - } + for ( num_digits = 0 ; num_digits < 3 ; ++num_digits) { + if ((*q < '0') || (*q > '7')) { /* not a digit? */ + break; + } + n = n * 8 + (*q++ - '0'); + } - if (num_digits == 0) { /* mnemonic escape sequence? */ - for (p=charmap ; *p ; p++) { - if (*p == *q) { - q++; - break; - } - } - n = *(p+(sizeof(charmap)/2)); - } + if (num_digits == 0) { /* mnemonic escape sequence? */ + for (p=charmap ; *p ; p++) { + if (*p == *q) { + q++; + break; + } + } + n = *(p+(sizeof(charmap)/2)); + } /* doesn't hurt to fall through to here from mnemonic case */ - if (n > UCHAR_MAX) { /* is octal code too big for a char? */ - n /= 8; /* adjust value and */ - --q; /* back up one char */ - } + if (n > UCHAR_MAX) { /* is octal code too big for a char? */ + n /= 8; /* adjust value and */ + --q; /* back up one char */ + } - *ptr = q; - return (char) n; + *ptr = q; + return (char) n; } diff --git a/libbb/xgetcwd.c b/libbb/xgetcwd.c new file mode 100644 index 0000000..2746681 --- /dev/null +++ b/libbb/xgetcwd.c @@ -0,0 +1,52 @@ +/* + * xgetcwd.c -- return current directory with unlimited length + * Copyright (C) 1992, 1996 Free Software Foundation, Inc. + * Written by David MacKenzie <djm@gnu.ai.mit.edu>. + * + * Special function for busybox written by Vladimir Oleynik <vodz@usa.net> +*/ + +#include <stdlib.h> +#include <errno.h> +#include <unistd.h> +#include <limits.h> +#include "libbb.h" + +/* Amount to increase buffer size by in each try. */ +#define PATH_INCR 32 + +/* Return the current directory, newly allocated, arbitrarily long. + Return NULL and set errno on error. + If argument is not NULL (previous usage allocate memory), call free() +*/ + +char * +xgetcwd (char *cwd) +{ + char *ret; + unsigned path_max; + + errno = 0; + path_max = (unsigned) PATH_MAX; + path_max += 2; /* The getcwd docs say to do this. */ + + if(cwd==0) + cwd = xmalloc (path_max); + + errno = 0; + while ((ret = getcwd (cwd, path_max)) == NULL && errno == ERANGE) { + path_max += PATH_INCR; + cwd = xrealloc (cwd, path_max); + errno = 0; + } + + if (ret == NULL) { + int save_errno = errno; + free (cwd); + errno = save_errno; + perror_msg("getcwd()"); + return NULL; + } + + return cwd; +} |