Apply Vladimir's latest cleanup patch.

-Erik
This commit is contained in:
Eric Andersen
2001-04-09 22:48:12 +00:00
parent a75e286743
commit e5dfced23a
30 changed files with 500 additions and 513 deletions

24
libbb/concat_path_file.c Normal file
View File

@ -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;
}

View File

@ -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__ */

View File

@ -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;
}

View File

@ -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', '\\', '\\' };
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;
const char *p;
const char *q;
int num_digits;
unsigned int n;
n = 0;
q = *ptr;
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;
}

52
libbb/xgetcwd.c Normal file
View File

@ -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;
}