exit( FALSE);
}
+#if defined BB_INIT
/* Returns kernel version encoded as major*65536 + minor*256 + patch,
* so, for example, to check if the kernel is greater than 2.2.11:
* if (get_kernel_revision() <= 2*65536+2*256+11) { <stuff> }
sscanf(name.version, "%d.%d.%d", &major, &minor, &patch);
return major * 65536 + minor * 256 + patch;
}
+#endif /* BB_INIT */
+#if defined (BB_CP_MV) || defined (BB_DU)
#define HASH_SIZE 311 /* Should be prime */
#define hash_inode(i) ((i) % HASH_SIZE)
}
}
+#endif /* BB_CP_MV || BB_DU */
+#if defined (BB_CP_MV) || defined (BB_DU) || defined (BB_LN)
/*
* Return TRUE if a fileName is a directory.
* Nonexistant files return FALSE.
}
return status;
}
+#endif
+#if defined (BB_CP_MV)
/*
* Copy one file to another, while possibly preserving its modes, times, and
* modes. Returns TRUE if successful, or FALSE on a failure with an error
return FALSE;
}
+#endif /* BB_CP_MV */
+
+#if defined BB_TAR || defined BB_LS
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
}
return buf;
}
+#endif /* BB_TAR || BB_LS */
+#if defined BB_TAR
/*
* Return the standard ls-like time string from a time_t
* This is static and so is overwritten on each call.
return buf;
}
+#endif /* BB_TAR */
+#if defined BB_TAR || defined BB_CP_MV
/*
* Write all of the supplied buffer out to a file.
* This does multiple writes as necessary.
return total;
}
+#endif /* BB_TAR || BB_CP_MV */
+#if defined BB_TAR || defined BB_TAIL
/*
* Read all of the supplied buffer from a file.
* This does multiple reads as necessary.
return total;
}
+#endif /* BB_TAR || BB_TAIL */
+#if defined (BB_CHMOD_CHOWN_CHGRP) \
+ || defined (BB_CP_MV) \
+ || defined (BB_FIND) \
+ || defined (BB_INSMOD) \
+ || defined (BB_RM) \
+ || defined (BB_TAR)
+
/*
* Walk down all the directories under the specified
* location, and do something (something specified
return TRUE;
}
+#endif /* BB_CHMOD_CHOWN_CHGRP || BB_CP_MV || BB_FIND || BB_LS || BB_INSMOD */
+#if defined (BB_TAR) || defined (BB_MKDIR)
/*
* Attempt to create the directories along the specified path, except for
* the final component. The mode is given for the final directory only,
}
return TRUE;
}
+#endif /* BB_TAR || BB_MKDIR */
+#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR)
/* [ugoa]{+|-|=}[rwxst] */
+
+
+
extern int parse_mode(const char *s, mode_t * theMode)
{
mode_t andMode =
}
+#endif /* BB_CHMOD_CHOWN_CHGRP || BB_MKDIR */
+
+
+#if defined BB_CHMOD_CHOWN_CHGRP || defined BB_PS || defined BB_LS || defined BB_TAR || defined BB_ID
+
/* This parses entries in /etc/passwd and /etc/group. This is desirable
* for BusyBox, since we want to avoid using the glibc NSS stuff, which
* increases target size and is often not needed or wanted for embedded
* This uses buf as storage to hold things.
*
*/
-uid_t my_getid(const char *filename, char *name, uid_t id, gid_t *gid)
+unsigned long my_getid(const char *filename, char *name, unsigned long id, unsigned long *gid)
{
FILE *file;
char *rname, *start, *end, buf[128];
- id_t rid;
- gid_t rgid = 0;
+ unsigned long rid;
+ unsigned long rgid = 0;
file = fopen(filename, "r");
if (file == NULL) {
- perror(filename);
+ /* Do not complain. It is ok for /etc/passwd and
+ * friends to be missing... */
return (-1);
}
/* uid in passwd, gid in group */
start = end + 1;
- rid = (uid_t) strtol(start, &end, 10);
+ rid = (unsigned long) strtol(start, &end, 10);
if (end == start)
continue;
/* gid in passwd */
start = end + 1;
- rgid = (gid_t) strtol(start, &end, 10);
+ rgid = (unsigned long) strtol(start, &end, 10);
if (name) {
if (0 == strcmp(rname, name)) {
}
/* returns a uid given a username */
-uid_t my_getpwnam(char *name)
+unsigned long my_getpwnam(char *name)
{
return my_getid("/etc/passwd", name, -1, NULL);
}
/* returns a gid given a group name */
-gid_t my_getgrnam(char *name)
+unsigned long my_getgrnam(char *name)
{
return my_getid("/etc/group", name, -1, NULL);
}
/* gets a username given a uid */
-void my_getpwuid(char *name, uid_t uid)
+void my_getpwuid(char *name, unsigned long uid)
{
my_getid("/etc/passwd", name, uid, NULL);
}
/* gets a groupname given a gid */
-void my_getgrgid(char *group, gid_t gid)
+void my_getgrgid(char *group, unsigned long gid)
{
my_getid("/etc/group", group, gid, NULL);
}
/* gets a gid given a user name */
-gid_t my_getpwnamegid(char *name)
+unsigned long my_getpwnamegid(char *name)
{
- gid_t gid;
+ unsigned long gid;
my_getid("/etc/passwd", name, -1, &gid);
return gid;
}
+#endif /* BB_CHMOD_CHOWN_CHGRP || BB_PS || BB_LS || BB_TAR || BB_ID */
+
+
+#if (defined BB_CHVT) || (defined BB_DEALLOCVT)
#include <linux/kd.h>
}
+#endif /* BB_CHVT || BB_DEALLOCVT */
-#if !defined BB_REGEXP
+#if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED)
+
/* Do a case insensitive strstr() */
char *stristr(char *haystack, const char *needle)
{
else
return FALSE;
}
-#endif /* ! BB_REGEXP */
+
+#endif /* ! BB_REGEXP && (BB_GREP || BB_SED) */
+#if defined BB_FIND
/*
* Routine to see if a text string is matched by a wildcard pattern.
* Returns TRUE if the text is matched, or FALSE if it is not matched
return TRUE;
}
+#endif /* BB_FIND */
+#if defined BB_DF || defined BB_MTAB
/*
* Given a block device, find the mount table entry if that block device
* is mounted.
endmntent(mountTable);
return mountEntry;
}
+#endif /* BB_DF || BB_MTAB */
+#if defined BB_DD || defined BB_TAIL
/*
* Read a number with a possible multiplier.
* Returns -1 if the number format is illegal.
return value;
}
+#endif /* BB_DD || BB_TAIL */
+#if defined BB_INIT || defined BB_SYSLOGD
/* try to open up the specified device */
extern int device_open(char *device, int mode)
{
fcntl(fd, F_SETFL, mode);
return fd;
}
+#endif /* BB_INIT BB_SYSLOGD */
+#if defined BB_KILLALL || ( defined BB_FEATURE_LINUXRC && ( defined BB_HALT || defined BB_REBOOT || defined BB_POWEROFF ))
#ifdef BB_FEATURE_USE_DEVPS_PATCH
#include <linux/devps.h>
+#endif
+#if defined BB_FEATURE_USE_DEVPS_PATCH
/* findPidByName()
*
* This finds the pid of the specified process,
return pidList;
}
#endif /* BB_FEATURE_USE_DEVPS_PATCH */
+#endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */
/* this should really be farmed out to libbusybox.a */
extern void *xmalloc(size_t size)
return cp;
}
-#if (__GLIBC__ < 2)
+#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
extern int vdprintf(int d, const char *format, va_list ap)
{
char buf[BUF_SIZE];
len = vsprintf(buf, format, ap);
return write(d, buf, len);
}
-#endif
+#endif /* BB_SYSLOGD */
+#if defined BB_FEATURE_MOUNT_LOOP
extern int del_loop(const char *device)
{
int fd;
}
return NULL;
}
+#endif /* BB_FEATURE_MOUNT_LOOP */
+#if defined BB_MOUNT || defined BB_DF || ( defined BB_UMOUNT && ! defined BB_MTAB)
extern int find_real_root_device_name(char* name)
{
DIR *dir;
return( FALSE);
}
+#endif
const unsigned int CSTRING_BUFFER_LENGTH = 128;
/* recursive parser that returns cstrings of arbitrary length
char *cstring;
char buffer[CSTRING_BUFFER_LENGTH];
int target = CSTRING_BUFFER_LENGTH * depth;
- int i, len;
- int size;
+ int c, i, len, size;
/* fill buffer */
i = 0;
- while ((buffer[i] = fgetc(f)) != EOF) {
+ while ((c = fgetc(f)) != EOF) {
+ buffer[i] = (char) c;
if (buffer[i++] == 0x0a) { break; }
if (i == CSTRING_BUFFER_LENGTH) { break; }
}