📄 list.c
字号:
} fprintf(msgfile, "%s", name); if ((asb->sb_nlink > 1) && (from = islink(name, asb))) { fprintf(msgfile, " linked to %s", from->l_name); }#ifdef S_IFLNK if ((asb->sb_mode & S_IFMT) == S_IFLNK) { fprintf(msgfile, " symbolic link to %s", asb->sb_link); }#endif /* S_IFLNK */ putc('\n', msgfile);}/* tar_entry - print a tar verbose mode entry * * DESCRIPTION * * Print_entry prints a single line of tar file information. The format * of the line is the same as that produced by the traditional tar * command. No error checking is done for bad or invalid data. * * PARAMETERS * * char *name - pointer to name to print an entry for * Stat *asb - pointer to the stat structure for the file */#ifdef __STDC__static void tar_entry(char *name, Stat *asb)#else static void tar_entry(name, asb)char *name;Stat *asb;#endif{ struct tm *atm; int i; int mode; char *symnam = "NULL"; Link *link; if ((mode = asb->sb_mode & S_IFMT) == S_IFDIR) { return; /* don't print directories */ } if (f_extract) { switch (mode) {#ifdef S_IFLNK case S_IFLNK: /* This file is a symbolic link */ i = readlink(name, symnam, PATH_MAX - 1); if (i < 0) { /* Could not find symbolic link */ warn("can't read symbolic link", strerror()); } else { /* Found symbolic link filename */ symnam[i] = '\0'; fprintf(msgfile, "x %s symbolic link to %s\n", name, symnam); } break;#endif case S_IFREG: /* It is a link or a file */ if ((asb->sb_nlink > 1) && (link = islink(name, asb))) { fprintf(msgfile, "%s linked to %s\n", name, link->l_name); } else { fprintf(msgfile, "x %s, %ld bytes, %d tape blocks\n", name, asb->sb_size, ROUNDUP(asb->sb_size, BLOCKSIZE) / BLOCKSIZE); } } } else if (f_append || f_create) { switch (mode) {#ifdef S_IFLNK case S_IFLNK: /* This file is a symbolic link */ i = readlink(name, symnam, PATH_MAX - 1); if (i < 0) { /* Could not find symbolic link */ warn("can't read symbolic link", strerror()); } else { /* Found symbolic link filename */ symnam[i] = '\0'; fprintf(msgfile, "a %s symbolic link to %s\n", name, symnam); } break;#endif case S_IFREG: /* It is a link or a file */ fprintf(msgfile, "a %s ", name); if ((asb->sb_nlink > 1) && (link = islink(name, asb))) { fprintf(msgfile, "link to %s\n", link->l_name); } else { fprintf(msgfile, "%ld Blocks\n", ROUNDUP(asb->sb_size, BLOCKSIZE) / BLOCKSIZE); } break; } } else if (f_list) { if (f_verbose) { atm = localtime(&asb->sb_mtime); print_mode(asb->sb_mode); fprintf(msgfile," %d/%d %6d %3s %2d %02d:%02d %4d %s", asb->sb_uid, asb->sb_gid, asb->sb_size, monnames[atm->tm_mon], atm->tm_mday, atm->tm_hour, atm->tm_min, atm->tm_year + 1900, name); } else { fprintf(msgfile, "%s", name); } switch (mode) {#ifdef S_IFLNK case S_IFLNK: /* This file is a symbolic link */ i = readlink(name, symnam, PATH_MAX - 1); if (i < 0) { /* Could not find symbolic link */ warn("can't read symbolic link", strerror()); } else { /* Found symbolic link filename */ symnam[i] = '\0'; fprintf(msgfile, " symbolic link to %s", symnam); } break;#endif case S_IFREG: /* It is a link or a file */ if ((asb->sb_nlink > 1) && (link = islink(name, asb))) { fprintf(msgfile, " linked to %s", link->l_name); } break; /* Do not print out directories */ } fputc('\n', msgfile); } else { fprintf(msgfile, "? %s %ld blocks\n", name, ROUNDUP(asb->sb_size, BLOCKSIZE) / BLOCKSIZE); }}/* pax_entry - print a verbose cpio-style entry * * DESCRIPTION * * Print_entry prints a single line of file information. The format * of the line is the same as that used by the LS command. * No error checking is done for bad or invalid data. * * PARAMETERS * * char *name - pointer to name to print an entry for * Stat *asb - pointer to the stat structure for the file */#ifdef __STDC__static void pax_entry(char *name, Stat *asb)#else static void pax_entry(name, asb)char *name;Stat *asb;#endif{ struct tm *atm; Link *from; struct passwd *pwp; struct group *grp; if (f_list && f_verbose) { print_mode(asb->sb_mode); fprintf(msgfile, " %2d", asb->sb_nlink); atm = localtime(&asb->sb_mtime); if (pwp = getpwuid((int) USH(asb->sb_uid))) { fprintf(msgfile, " %-8s", pwp->pw_name); } else { fprintf(msgfile, " %-8u", USH(asb->sb_uid)); } if (grp = getgrgid((int) USH(asb->sb_gid))) { fprintf(msgfile, " %-8s", grp->gr_name); } else { fprintf(msgfile, " %-8u", USH(asb->sb_gid)); } switch (asb->sb_mode & S_IFMT) { case S_IFBLK: case S_IFCHR: fprintf(msgfile, "\t%3d, %3d", major(asb->sb_rdev), minor(asb->sb_rdev)); break; case S_IFREG: fprintf(msgfile, "\t%8ld", asb->sb_size); break; default: fprintf(msgfile, "\t "); } fprintf(msgfile," %3s %2d %02d:%02d ", monnames[atm->tm_mon], atm->tm_mday, atm->tm_hour, atm->tm_min); } fprintf(msgfile, "%s", name); if ((asb->sb_nlink > 1) && (from = islink(name, asb))) { fprintf(msgfile, " == %s", from->l_name); }#ifdef S_IFLNK if ((asb->sb_mode & S_IFMT) == S_IFLNK) { fprintf(msgfile, " -> %s", asb->sb_link); }#endif /* S_IFLNK */ putc('\n', msgfile);}/* print_mode - fancy file mode display * * DESCRIPTION * * Print_mode displays a numeric file mode in the standard unix * representation, ala ls (-rwxrwxrwx). No error checking is done * for bad mode combinations. FIFOS, sybmbolic links, sticky bits, * block- and character-special devices are supported if supported * by the hosting implementation. * * PARAMETERS * * ushort mode - The integer representation of the mode to print. */#ifdef __STDC__static void print_mode(ushort mode)#else static void print_mode(mode)ushort mode;#endif{ /* Tar does not print the leading identifier... */ if (ar_interface != TAR) { switch (mode & S_IFMT) { case S_IFDIR: putc('d', msgfile); break;#ifdef S_IFLNK case S_IFLNK: putc('l', msgfile); break;#endif /* S_IFLNK */ case S_IFBLK: putc('b', msgfile); break; case S_IFCHR: putc('c', msgfile); break;#ifdef S_IFIFO case S_IFIFO: putc('p', msgfile); break; #endif /* S_IFIFO */ case S_IFREG: default: putc('-', msgfile); break; } } putc(mode & 0400 ? 'r' : '-', msgfile); putc(mode & 0200 ? 'w' : '-', msgfile); putc(mode & 0100 ? mode & 04000 ? 's' : 'x' : mode & 04000 ? 'S' : '-', msgfile); putc(mode & 0040 ? 'r' : '-', msgfile); putc(mode & 0020 ? 'w' : '-', msgfile); putc(mode & 0010 ? mode & 02000 ? 's' : 'x' : mode & 02000 ? 'S' : '-', msgfile); putc(mode & 0004 ? 'r' : '-', msgfile); putc(mode & 0002 ? 'w' : '-', msgfile); putc(mode & 0001 ? mode & 01000 ? 't' : 'x' : mode & 01000 ? 'T' : '-', msgfile);}/* from_oct - quick and dirty octal conversion * * DESCRIPTION * * From_oct will convert an ASCII representation of an octal number * to the numeric representation. The number of characters to convert * is given by the parameter "digs". If there are less numbers than * specified by "digs", then the routine returns -1. * * PARAMETERS * * int digs - Number to of digits to convert * char *where - Character representation of octal number * * RETURNS * * The value of the octal number represented by the first digs * characters of the string where. Result is -1 if the field * is invalid (all blank, or nonoctal). * * ERRORS * * If the field is all blank, then the value returned is -1. * */#ifdef __STDC__static long from_oct(int digs, char *where)#elsestatic long from_oct(digs, where)int digs; /* number of characters to convert */char *where; /* character representation of octal number */#endif{ long value; while (isspace(*where)) { /* Skip spaces */ where++; if (--digs <= 0) { return(-1); /* All blank field */ } } value = 0; while (digs > 0 && ISODIGIT(*where)) { /* Scan til nonoctal */ value = (value << 3) | (*where++ - '0'); --digs; } if (digs > 0 && *where && !isspace(*where)) { return(-1); /* Ended on non-space/nul */ } return(value);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -