Annotation of 43BSDReno/lib/libc/string/strmode.c, revision 1.1.1.1

1.1       root        1: /*-
                      2:  * Copyright (c) 1990 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #if defined(LIBC_SCCS) && !defined(lint)
                     21: static char sccsid[] = "@(#)strmode.c  5.3 (Berkeley) 5/18/90";
                     22: #endif /* LIBC_SCCS and not lint */
                     23: 
                     24: #include <sys/types.h>
                     25: #include <sys/stat.h>
                     26: #include <string.h>
                     27: 
                     28: void
                     29: strmode(mode, p)
                     30:        register mode_t mode;
                     31:        register char *p;
                     32: {
                     33:         /* print type */
                     34:        switch (mode & S_IFMT) {
                     35:        case S_IFDIR:                   /* directory */
                     36:                *p++ = 'd';
                     37:                break;
                     38:        case S_IFCHR:                   /* character special */
                     39:                *p++ = 'c';
                     40:                break;
                     41:        case S_IFBLK:                   /* block special */
                     42:                *p++ = 'b';
                     43:                break;
                     44:        case S_IFREG:                   /* regular */
                     45:                *p++ = '-';
                     46:                break;
                     47:        case S_IFLNK:                   /* symbolic link */
                     48:                *p++ = 'l';
                     49:                break;
                     50:        case S_IFSOCK:                  /* socket */
                     51:                *p++ = 's';
                     52:                break;
                     53: #ifdef S_IFIFO
                     54:        case S_IFIFO:                   /* fifo */
                     55:                *p++ = 'p';
                     56:                break;
                     57: #endif
                     58:        default:                        /* unknown */
                     59:                *p++ = '?';
                     60:                break;
                     61:        }
                     62:        /* usr */
                     63:        if (mode & S_IRUSR)
                     64:                *p++ = 'r';
                     65:        else
                     66:                *p++ = '-';
                     67:        if (mode & S_IWUSR)
                     68:                *p++ = 'w';
                     69:        else
                     70:                *p++ = '-';
                     71:        switch (mode & (S_IXUSR | S_ISUID)) {
                     72:        case 0:
                     73:                *p++ = '-';
                     74:                break;
                     75:        case S_IXUSR:
                     76:                *p++ = 'x';
                     77:                break;
                     78:        case S_ISUID:
                     79:                *p++ = 'S';
                     80:                break;
                     81:        case S_IXUSR | S_ISUID:
                     82:                *p++ = 's';
                     83:                break;
                     84:        }
                     85:        /* group */
                     86:        if (mode & S_IRGRP)
                     87:                *p++ = 'r';
                     88:        else
                     89:                *p++ = '-';
                     90:        if (mode & S_IWGRP)
                     91:                *p++ = 'w';
                     92:        else
                     93:                *p++ = '-';
                     94:        switch (mode & (S_IXGRP | S_ISGID)) {
                     95:        case 0:
                     96:                *p++ = '-';
                     97:                break;
                     98:        case S_IXGRP:
                     99:                *p++ = 'x';
                    100:                break;
                    101:        case S_ISGID:
                    102:                *p++ = 'S';
                    103:                break;
                    104:        case S_IXGRP | S_ISGID:
                    105:                *p++ = 's';
                    106:                break;
                    107:        }
                    108:        /* other */
                    109:        if (mode & S_IROTH)
                    110:                *p++ = 'r';
                    111:        else
                    112:                *p++ = '-';
                    113:        if (mode & S_IWOTH)
                    114:                *p++ = 'w';
                    115:        else
                    116:                *p++ = '-';
                    117:        switch (mode & (S_IXOTH | S_ISVTX)) {
                    118:        case 0:
                    119:                *p++ = '-';
                    120:                break;
                    121:        case S_IXOTH:
                    122:                *p++ = 'x';
                    123:                break;
                    124:        case S_ISVTX:
                    125:                *p++ = 'T';
                    126:                break;
                    127:        case S_IXOTH | S_ISVTX:
                    128:                *p++ = 't';
                    129:                break;
                    130:        }
                    131:        *p++ = ' ';             /* will be a '+' if ACL's implemented */
                    132:        *p = '\0';
                    133: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.