diff options
Diffstat (limited to 'bin/pax/gen_subs.c')
-rw-r--r-- | bin/pax/gen_subs.c | 72 |
1 files changed, 23 insertions, 49 deletions
diff --git a/bin/pax/gen_subs.c b/bin/pax/gen_subs.c index a22bd96..3ddab8c 100644 --- a/bin/pax/gen_subs.c +++ b/bin/pax/gen_subs.c @@ -83,12 +83,13 @@ static int d_first = -1; #ifdef __STDC__ void -ls_list(register ARCHD *arcn, time_t now) +ls_list(register ARCHD *arcn, time_t now, FILE *fp) #else void -ls_list(arcn, now) +ls_list(arcn, now, fp) register ARCHD *arcn; time_t now; + FILE *fp; #endif { register struct stat *sbp; @@ -100,8 +101,8 @@ ls_list(arcn, now) * if not verbose, just print the file name */ if (!vflag) { - (void)printf("%s\n", arcn->name); - (void)fflush(stdout); + (void)fprintf(fp, "%s\n", arcn->name); + (void)fflush(fp); return; } @@ -126,8 +127,8 @@ ls_list(arcn, now) */ if (strftime(f_date,DATELEN,timefrmt,localtime(&(sbp->st_mtime))) == 0) f_date[0] = '\0'; - (void)printf("%s%2u %-*s %-*s ", f_mode, sbp->st_nlink, UT_NAMESIZE, - name_uid(sbp->st_uid, 1), UT_GRPSIZE, + (void)fprintf(fp, "%s%2u %-*s %-*s ", f_mode, sbp->st_nlink, + UT_NAMESIZE, name_uid(sbp->st_uid, 1), UT_GRPSIZE, name_gid(sbp->st_gid, 1)); /* @@ -135,31 +136,31 @@ ls_list(arcn, now) */ if ((arcn->type == PAX_CHR) || (arcn->type == PAX_BLK)) # ifdef NET2_STAT - (void)printf("%4u,%4u ", MAJOR(sbp->st_rdev), + (void)fprintf(fp, "%4u,%4u ", MAJOR(sbp->st_rdev), MINOR(sbp->st_rdev)); # else - (void)printf("%4lu,%4lu ", (unsigned long)MAJOR(sbp->st_rdev), + (void)fprintf(fp, "%4lu,%4lu ", (unsigned long)MAJOR(sbp->st_rdev), (unsigned long)MINOR(sbp->st_rdev)); # endif else { # ifdef NET2_STAT - (void)printf("%9lu ", sbp->st_size); + (void)fprintf(fp, "%9lu ", sbp->st_size); # else - (void)printf("%9qu ", sbp->st_size); + (void)fprintf(fp, "%9qu ", sbp->st_size); # endif } /* * print name and link info for hard and soft links */ - (void)printf("%s %s", f_date, arcn->name); + (void)fprintf(fp, "%s %s", f_date, arcn->name); if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG)) - (void)printf(" == %s\n", arcn->ln_name); + (void)fprintf(fp, " == %s\n", arcn->ln_name); else if (arcn->type == PAX_SLK) - (void)printf(" => %s\n", arcn->ln_name); + (void)fprintf(fp, " => %s\n", arcn->ln_name); else - (void)putchar('\n'); - (void)fflush(stdout); + (void)putc('\n', fp); + (void)fflush(fp); return; } @@ -201,40 +202,12 @@ ls_tty(arcn) } /* - * zf_strncpy() - * copy src to dest up to len chars (stopping at first '\0'), when src is - * shorter than len, pads to len with '\0'. big performance win (and - * a lot easier to code) over strncpy(), then a strlen() then a - * memset(). (or doing the memset() first). - */ - -#ifdef __STDC__ -void -zf_strncpy(register char *dest, register char *src, int len) -#else -void -zf_strncpy(dest, src, len) - register char *dest; - register char *src; - int len; -#endif -{ - register char *stop; - - stop = dest + len; - while ((dest < stop) && (*src != '\0')) - *dest++ = *src++; - while (dest < stop) - *dest++ = '\0'; - return; -} - -/* * l_strncpy() - * copy src to dest up to len chars (stopping at first '\0') + * copy src to dest up to len chars (stopping at first '\0'). + * when src is shorter than len, pads to len with '\0'. * Return: * number of chars copied. (Note this is a real performance win over - * doing a strncpy() then a strlen() + * doing a strncpy(), a strlen(), and then a possible memset()) */ #ifdef __STDC__ @@ -255,9 +228,10 @@ l_strncpy(dest, src, len) start = dest; while ((dest < stop) && (*src != '\0')) *dest++ = *src++; - if (dest < stop) - *dest = '\0'; - return(dest - start); + len = dest - start; + while (dest < stop) + *dest++ = '\0'; + return(len); } /* |