* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-//#include <sys/types.h>
-
#include "libbb.h"
#include "unarchive.h"
-void data_align(archive_handle_t *archive_handle, const unsigned short boundary)
+void data_align(archive_handle_t *archive_handle, unsigned boundary)
{
- const unsigned short skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
+ unsigned skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
archive_handle->seek(archive_handle, skip_amount);
archive_handle->offset += skip_amount;
if (gzipPid == 0) {
/* child */
- xmove_fd(tbInfo.tarFd, 1);
- xmove_fd(gzipDataPipe.rd, 0);
+ /* NB: close _first_, then move fds! */
close(gzipDataPipe.wr);
#if WAIT_FOR_CHILD
close(gzipStatusPipe.rd);
+ /* gzipStatusPipe.wr will close only on exec -
+ * parent waits for this close to happen */
fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);
#endif
+ xmove_fd(gzipDataPipe.rd, 0);
+ xmove_fd(tbInfo.tarFd, 1);
/* exec gzip/bzip2 program/applet */
BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
vfork_exec_errno = errno;
/* Wait until child execs (or fails to) */
n = full_read(gzipStatusPipe.rd, &buf, 1);
- if ((n < 0) && (/*errno == EAGAIN ||*/ errno == EINTR))
+ if (n < 0 /* && errno == EAGAIN */)
continue; /* try it again */
}
lib-$(CONFIG_CAT) += cat.o
lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty
lib-$(CONFIG_LESS) += cat.o # less too
+lib-$(CONFIG_CRONTAB) += cat.o # crontab -l
lib-$(CONFIG_CATV) += catv.o
lib-$(CONFIG_CHGRP) += chgrp.o chown.o
lib-$(CONFIG_CHMOD) += chmod.o
FILE *sw_file; /* File (sw) command writes to, -1 for none. */
char *string; /* Data string for (saicytb) commands. */
- unsigned short which_match; /* (s) Which match to replace (0 for all) */
+ unsigned which_match; /* (s) Which match to replace (0 for all) */
/* Bitfields (gcc won't group them if we don't) */
unsigned invert:1; /* the '!' after the address */
/* Match 0 treated as all, multiple matches we take the last one. */
const char *pos = substr + idx;
/* FIXME: error check? */
- sed_cmd->which_match = (unsigned short)strtol(substr+idx, (char**) &pos, 10);
+ sed_cmd->which_match = (unsigned)strtol(substr+idx, (char**) &pos, 10);
idx = pos - substr;
}
continue;
switch (substr[idx]) {
/* Replace all occurrences */
case 'g':
- if (match[0] != '^') sed_cmd->which_match = 0;
+ if (match[0] != '^')
+ sed_cmd->which_match = 0;
break;
/* Print pattern space */
case 'p':
altered++;
/* if we're not doing this globally, get out now */
- if (sed_cmd->which_match) break;
+ if (sed_cmd->which_match)
+ break;
} while (*oldline && (regexec(current_regex, oldline, 10, G.regmatch, 0) != REG_NOMATCH));
/* Copy rest of string into output pipeline */
pid_t spawn(char **argv);
pid_t xspawn(char **argv);
-/* Unlike waitpid, waits ONLY for one process,
+int safe_waitpid(int pid, int *wstat, int options);
+/* Unlike waitpid, waits ONLY for one process.
* It's safe to pass negative 'pids' from failed [v]fork -
* wait4pid will return -1 (and will not clobber [v]fork's errno).
* IOW: rc = wait4pid(spawn(argv));
* if (rc < 0) bb_perror_msg("%s", argv[0]);
* if (rc > 0) bb_error_msg("exit code: %d", rc);
*/
-int safe_waitpid(int pid, int *wstat, int options);
int wait4pid(int pid);
int wait_any_nohang(int *wstat);
#define wait_crashed(w) ((w) & 127)
extern ssize_t archive_xread_all_eof(archive_handle_t *archive_handle, unsigned char *buf, size_t count);
-extern void data_align(archive_handle_t *archive_handle, const unsigned short boundary);
+extern void data_align(archive_handle_t *archive_handle, unsigned boundary);
extern const llist_t *find_list_entry(const llist_t *list, const char *filename);
extern const llist_t *find_list_entry2(const llist_t *list, const char *filename);
static void dump_identity(const struct hd_driveid *id)
{
int i;
- const unsigned short int *id_regs = (const void*) id;
+ const unsigned short *id_regs = (const void*) id;
printf("\n Model=%.40s, FwRev=%.8s, SerialNo=%.20s\n Config={",
id->model, id->fw_rev, id->serial_no);
static int xconnect_ftpdata(ftp_host_info_t *server, char *buf)
{
char *buf_ptr;
- unsigned short port_num;
+ unsigned port_num;
/* Response is "NNN garbageN1,N2,N3,N4,P1,P2[)garbage]
* Server's IP is N1.N2.N3.N4 (we ignore it)
/* Child process */
xfunc_error_retval = 242;
+ /* NB: close _first_, then move fds! */
+ close(toCgi.wr);
+ close(fromCgi.rd);
xmove_fd(toCgi.rd, 0); /* replace stdin with the pipe */
xmove_fd(fromCgi.wr, 1); /* replace stdout with the pipe */
- close(fromCgi.rd);
- close(toCgi.wr);
/* User seeing stderr output can be a security problem.
* If CGI really wants that, it can always do dup itself. */
/* dup2(1, 2); */
id = ntohs(id);
- for (i=0; i < ARRAY_SIZE(llproto_names); i++) {
+ for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
if (llproto_names[i].id == id)
return llproto_names[i].name;
}
int ll_proto_a2n(unsigned short *id, char *buf)
{
int i;
- for (i=0; i < ARRAY_SIZE(llproto_names); i++) {
+ for (i = 0; i < ARRAY_SIZE(llproto_names); i++) {
if (strcasecmp(llproto_names[i].name, buf) == 0) {
*id = htons(llproto_names[i].id);
return 0;
#endif
struct dn_naddr {
- unsigned short a_len;
- unsigned char a_addr[DN_MAXADDL];
+ unsigned short a_len;
+ unsigned char a_addr[DN_MAXADDL];
};
#define IPX_NODE_LEN 6
if (pid == 0) { /* child */
if (ENABLE_HUSH_JOB)
die_sleep = 0; /* let nofork's xfuncs die */
- close(channel[0]);
+ close(channel[0]); /* NB: close _first_, then move fd! */
xmove_fd(channel[1], 1);
/* Prevent it from trying to handle ctrl-z etc */
#if ENABLE_HUSH_JOB
if (!bltin)
export(lookup(cp));
- if (pin) {
+ if (pin) { /* NB: close _first_, then move fds! */
+ close(pin[1]);
xmove_fd(pin[0], 0);
- if (pin[1] != 0)
- close(pin[1]);
}
if (pout) {
+ close(pout[0]);
xmove_fd(pout[1], 1);
- if (pout[0] > 1)
- close(pout[0]);
}
iopp = t->ioact;
* Some fixes
*/
-static int aix_other_endian;
-static short aix_volumes = 1;
+static smallint aix_other_endian; /* bool */
+static smallint aix_volumes = 1; /* max 15 */
/*
* only dealing with free blocks here
#if ENABLE_FEATURE_SGI_LABEL
+#define SGI_DEBUG 0
+
/*
* Copyright (C) Andreas Neuper, Sep 1998.
* This file may be modified and redistributed under
*/
-static int sgi_other_endian;
-static int debug;
-static short sgi_volumes = 1;
+static smallint sgi_other_endian; /* bool */
+static smallint sgi_volumes = 1; /* max 15 */
/*
* only dealing with free blocks here
"Pt# %*s Info Start End Sectors Id System\n",
w + 2, "Device");
for (i = 0; i < g_partitions; i++) {
- if (sgi_get_num_sectors(i) || debug ) {
+ if (sgi_get_num_sectors(i) || SGI_DEBUG) {
uint32_t start = sgi_get_start_sector(i);
uint32_t len = sgi_get_num_sectors(i);
kpi++; /* only count nonempty partitions */
"at block 0,\n"
"not at diskblock %d\n",
sgi_get_start_sector(Index[0]));
- if (debug) /* I do not understand how some disks fulfil it */
+ if (SGI_DEBUG) /* I do not understand how some disks fulfil it */
if ((sgi_get_num_sectors(Index[0]) != lastblock) && verbose)
printf("The entire disk partition is only %d diskblock large,\n"
"but the disk is %d diskblocks long\n",
} else {
if (verbose)
printf("One Partition (#11) should cover the entire disk\n");
- if (debug > 2)
+ if (SGI_DEBUG > 2)
printf("sysid=%d\tpartition=%d\n",
sgi_get_sysid(Index[0]), Index[0]+1);
}
int cylsize = sgi_get_nsect() * sgi_get_ntrks();
if ((sgi_get_start_sector(Index[i]) % cylsize) != 0) {
- if (debug) /* I do not understand how some disks fulfil it */
+ if (SGI_DEBUG) /* I do not understand how some disks fulfil it */
if (verbose)
printf("Partition %d does not start on cylinder boundary\n",
Index[i]+1);
}
if (sgi_get_num_sectors(Index[i]) % cylsize != 0) {
- if (debug) /* I do not understand how some disks fulfil it */
+ if (SGI_DEBUG) /* I do not understand how some disks fulfil it */
if (verbose)
printf("Partition %d does not end on cylinder boundary\n",
Index[i]+1);
}
start = sgi_get_start_sector(Index[i])
+ sgi_get_num_sectors(Index[i]);
- if (debug > 1) {
+ if (SGI_DEBUG > 1) {
if (verbose)
printf("%2d:%12d\t%12d\t%12d\n", Index[i],
sgi_get_start_sector(Index[i]),
old[i].start = get_start_sect(get_part_table(i));
old[i].nsect = get_nr_sects(get_part_table(i));
printf("Trying to keep parameters of partition %d\n", i);
- if (debug)
+ if (SGI_DEBUG)
printf("ID=%02x\tSTART=%d\tLENGTH=%d\n",
old[i].sysid, old[i].start, old[i].nsect);
}
union semun {
int val;
struct semid_ds *buf;
- unsigned short int *array;
+ unsigned short *array;
struct seminfo *__buf;
};
#endif
union semun {
int val;
struct semid_ds *buf;
- unsigned short int *array;
+ unsigned short *array;
struct seminfo *__buf;
};
#endif