/* same conditions as recursiveAction */
#define bb_need_name_too_long
#endif
+#define bb_need_memory_exhausted
#define BB_DECLARE_EXTERN
#include "messages.c"
}
#endif /* BB_INIT */
+
+
+#if defined BB_FREE || defined BB_INIT || defined BB_UNAME || defined BB_UPTIME
+#include <sys/syscall.h>
+_syscall1(int, sysinfo, struct sysinfo *, info);
+#endif /* BB_INIT */
+
+
+
#if defined (BB_CP_MV) || defined (BB_DU)
#define HASH_SIZE 311 /* Should be prime */
#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 message output. (Failure is not indicated if the attributes cannot
- * be set.)
- * -Erik Andersen
+ * 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
+ * message output. (Failure is not indicated if attributes cannot be set.)
+ * -Erik Andersen
*/
int
copyFile(const char *srcName, const char *destName,
- int setModes, int followLinks)
+ int setModes, int followLinks, int forceFlag)
{
int rfd;
int wfd;
else
status = lstat(destName, &dstStatBuf);
- if (status < 0) {
+ if (status < 0 || forceFlag==TRUE) {
+ unlink(destName);
dstStatBuf.st_ino = -1;
dstStatBuf.st_dev = -1;
}
}
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
if (setModes == TRUE) {
- if (lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) {
- perror(destName);
- return FALSE;
- }
+ /* Try to set owner, but fail silently like GNU cp */
+ lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid);
}
#endif
return TRUE;
* 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;
}
while (where != NULL) {
foundOne++;
strcpy(oldhayStack, haystack);
-#if 0
- if (strlen(newNeedle) > strlen(needle)) {
- haystack =
- (char *) realloc(haystack,
- (unsigned) (strlen(haystack) -
- strlen(needle) +
- strlen(newNeedle)));
- }
-#endif
for (slider = haystack, slider1 = oldhayStack; slider != where;
slider++, slider1++);
*slider = 0;
#endif /* ! BB_REGEXP && (BB_GREP || BB_SED) */
-#if defined BB_FIND
+#if defined BB_FIND || defined BB_INSMOD
/*
* 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 */
+#endif /* BB_FIND || BB_INSMOD */
return 0;
while ((mountEntry = getmntent(mountTable)) != 0) {
+ if (strcmp(mountEntry->mnt_fsname, "none") == 0) {
+ continue;
+ }
if (strcmp(name, mountEntry->mnt_dir) == 0
|| strcmp(name, mountEntry->mnt_fsname) == 0) /* String match. */
break;
&& (strlen(pidName) == strlen(info.command_line))) {
pidList=realloc( pidList, sizeof(pid_t) * (j+2));
if (pidList==NULL)
- fatalError("out of memory\n");
+ fatalError(memory_exhausted, "");
pidList[j++]=info.pid;
}
}
&& (strlen(pidName) == strlen(p))) {
pidList=realloc( pidList, sizeof(pid_t) * (i+2));
if (pidList==NULL)
- fatalError("out of memory\n");
+ fatalError(memory_exhausted, "");
pidList[i++]=strtol(next->d_name, NULL, 0);
}
}
void *cp = malloc(size);
if (cp == NULL)
- fatalError("out of memory\n");
+ fatalError(memory_exhausted, "");
return cp;
}
}
#endif /* BB_FEATURE_MOUNT_LOOP */
-#if defined BB_MOUNT || defined BB_DF
+#if defined BB_MOUNT || defined BB_DF || ( defined BB_UMOUNT && ! defined BB_MTAB)
extern int find_real_root_device_name(char* name)
{
DIR *dir;
}
#endif
-const unsigned int CSTRING_BUFFER_LENGTH = 128;
+const unsigned int CSTRING_BUFFER_LENGTH = 1024;
/* recursive parser that returns cstrings of arbitrary length
* from a FILE*
*/
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; }
}