const char *, fstype, unsigned long int, rwflag, const void *, data);
#endif
+#if defined BB_INSMOD || defined BB_LSMOD
+#ifndef __NR_query_module
+#define __NR_query_module 167
+#endif
+_syscall5(int, query_module, const char *, name, int, which,
+ void *, buf, size_t, bufsize, size_t*, ret);
+#endif
#if defined (BB_CP_MV) || defined (BB_DU)
}
#endif
+#if defined (BB_AR) || defined BB_CP_MV
+/*
+ * Copy readSize bytes between two file descriptors
+ */
+int copySubFile(int srcFd, int dstFd, size_t remaining)
+{
+ size_t size;
+ char buffer[BUFSIZ];
+
+ while (remaining > 0) {
+ if (remaining > BUFSIZ)
+ size = BUFSIZ;
+ else
+ size = remaining;
+ if (fullWrite(dstFd, buffer, fullRead(srcFd, buffer, size)) < size)
+ return(FALSE);
+ remaining -= size;
+ }
+ return (TRUE);
+}
+#endif
+
+
#if defined (BB_CP_MV)
/*
* Copy one file to another, while possibly preserving its modes, times, and
{
int rfd;
int wfd;
- int rcc;
int status;
- char buf[BUF_SIZE];
struct stat srcStatBuf;
struct stat dstStatBuf;
struct utimbuf times;
return FALSE;
}
- wfd =
- open(destName, O_WRONLY | O_CREAT | O_TRUNC,
+ wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC,
srcStatBuf.st_mode);
if (wfd < 0) {
perror(destName);
return FALSE;
}
- while ((rcc = read(rfd, buf, sizeof(buf))) > 0) {
- if (fullWrite(wfd, buf, rcc) < 0)
- goto error_exit;
- }
- if (rcc < 0) {
- goto error_exit;
- }
-
+ if (copySubFile(rfd, wfd, srcStatBuf.st_size)==FALSE)
+ goto error_exit;
+
close(rfd);
if (close(wfd) < 0) {
return FALSE;
-#if defined BB_TAR || defined BB_LS
+#if defined BB_TAR || defined BB_LS ||defined BB_AR
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
#endif /* BB_TAR || BB_CP_MV || BB_AR */
-#if defined BB_TAR || defined BB_TAIL || defined BB_AR || defined BB_SH
+#if defined BB_TAR || defined BB_TAIL || defined BB_AR || defined BB_SH || defined BB_CP_MV
/*
* Read all of the supplied buffer from a file.
* This does multiple reads as necessary.
#if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_MKDIR) \
- || defined (BB_MKFIFO) || defined (BB_MKNOD)
+ || defined (BB_MKFIFO) || defined (BB_MKNOD) || defined (BB_AR)
/* [ugoa]{+|-|=}[rwxst] */
char type;
char c;
+ if (s==NULL)
+ return (FALSE);
+
do {
for (;;) {
switch (c = *s++) {
#endif /* BB_CHVT || BB_DEALLOCVT || BB_SETKEYCODES */
-#if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED)
-
-/* Do a case insensitive strstr() */
-char *stristr(char *haystack, const char *needle)
-{
- int len = strlen(needle);
-
- while (*haystack) {
- if (!strncasecmp(haystack, needle, len))
- break;
- haystack++;
- }
-
- if (!(*haystack))
- haystack = NULL;
-
- return haystack;
-}
-
-/* This tries to find a needle in a haystack, but does so by
- * only trying to match literal strings (look 'ma, no regexps!)
- * This is short, sweet, and carries _very_ little baggage,
- * unlike its beefier cousin in regexp.c
- * -Erik Andersen
- */
-extern int find_match(char *haystack, char *needle, int ignoreCase)
-{
-
- if (ignoreCase == FALSE)
- haystack = strstr(haystack, needle);
- else
- haystack = stristr(haystack, needle);
- if (haystack == NULL)
- return FALSE;
- return TRUE;
-}
-
-
-/* This performs substitutions after a string match has been found. */
-extern int replace_match(char *haystack, char *needle, char *newNeedle,
- int ignoreCase)
-{
- int foundOne = 0;
- char *where, *slider, *slider1, *oldhayStack;
-
- if (ignoreCase == FALSE)
- where = strstr(haystack, needle);
- else
- where = stristr(haystack, needle);
-
- if (strcmp(needle, newNeedle) == 0)
- return FALSE;
-
- oldhayStack = (char *) xmalloc((unsigned) (strlen(haystack)));
- while (where != NULL) {
- foundOne++;
- strcpy(oldhayStack, haystack);
- for (slider = haystack, slider1 = oldhayStack; slider != where;
- slider++, slider1++);
- *slider = 0;
- haystack = strcat(haystack, newNeedle);
- slider1 += strlen(needle);
- haystack = strcat(haystack, slider1);
- where = strstr(slider, needle);
- }
- free(oldhayStack);
-
- if (foundOne > 0)
- return TRUE;
- else
- return FALSE;
-}
-
-#endif /* ! BB_REGEXP && (BB_GREP || BB_SED) */
-
-
#if defined BB_FIND || defined BB_INSMOD
/*
* Routine to see if a text string is matched by a wildcard pattern.
#endif /* BB_DD || BB_TAIL */
-#if defined BB_INIT || defined BB_SYSLOGD || defined BB_AR
+#if defined BB_INIT || defined BB_SYSLOGD
/* try to open up the specified device */
extern int device_open(char *device, int mode)
{
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
- pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
+ pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */
if ((strstr(info.command_line, pidName) != NULL)
&& (strlen(pidName) == strlen(info.command_line))) {
- pidList=realloc( pidList, sizeof(pid_t) * (j+2));
- if (pidList==NULL)
- fatalError(memory_exhausted);
+ pidList=xrealloc( pidList, sizeof(pid_t) * (j+2));
pidList[j++]=info.pid;
}
}
FILE *status;
char filename[256];
char buffer[256];
- char* p;
/* If it isn't a number, we don't want it */
if (!isdigit(*next->d_name))
continue;
- /* Now open the status file */
- sprintf(filename, "/proc/%s/status", next->d_name);
+ sprintf(filename, "/proc/%s/cmdline", next->d_name);
status = fopen(filename, "r");
if (!status) {
continue;
fgets(buffer, 256, status);
fclose(status);
- /* Make sure we only match on the process name */
- p=buffer+5; /* Skip the name */
- while ((p)++) {
- if (*p==0 || *p=='\n') {
- *p='\0';
- break;
- }
- }
- p=buffer+6; /* Skip the "Name:\t" */
-
- if ((strstr(p, pidName) != NULL)
- && (strlen(pidName) == strlen(p))) {
- pidList=realloc( pidList, sizeof(pid_t) * (i+2));
- if (pidList==NULL)
- fatalError(memory_exhausted);
+ if (strstr(get_last_path_component(buffer), pidName) != NULL) {
+ pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
pidList[i++]=strtol(next->d_name, NULL, 0);
}
}
+
if (pidList)
pidList[i]=0;
return pidList;
}
#endif
-#if defined BB_FEATURE_NFSMOUNT
+#if defined BB_FEATURE_NFSMOUNT || defined BB_SH || defined BB_LS
# ifndef DMALLOC
extern char * xstrdup (const char *s) {
char *t;
return t;
}
# endif
+#endif
+#if defined BB_FEATURE_NFSMOUNT
extern char * xstrndup (const char *s, int n) {
char *t;
break;
/* grow the line buffer as necessary */
if (idx > linebufsz-2)
- linebuf = realloc(linebuf, linebufsz += GROWBY);
+ linebuf = xrealloc(linebuf, linebufsz += GROWBY);
linebuf[idx++] = (char)ch;
if ((char)ch == '\n')
break;
}
#endif
-#if defined BB_BASENAME || defined BB_LN
+#if defined BB_BASENAME || defined BB_LN || defined BB_SH
char *get_last_path_component(char *path)
{
char *s=path+strlen(path)-1;