[BACK]Return to strmode.c CVS log [TXT][DIR] Up to [local] / prex-old / usr / lib / libc / string

Annotation of prex-old/usr/lib/libc/string/strmode.c, Revision 1.1.1.1

1.1       nbrk        1: /*-
                      2:  * Copyright (c) 1990, 1993
                      3:  *     The Regents of the University of California.  All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms, with or without
                      6:  * modification, are permitted provided that the following conditions
                      7:  * are met:
                      8:  * 1. Redistributions of source code must retain the above copyright
                      9:  *    notice, this list of conditions and the following disclaimer.
                     10:  * 2. Redistributions in binary form must reproduce the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer in the
                     12:  *    documentation and/or other materials provided with the distribution.
                     13:  * 3. Neither the name of the University nor the names of its contributors
                     14:  *    may be used to endorse or promote products derived from this software
                     15:  *    without specific prior written permission.
                     16:  *
                     17:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     18:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     19:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     20:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     21:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     22:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     23:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     24:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     25:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     26:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     27:  * SUCH DAMAGE.
                     28:  */
                     29:
                     30: #include <sys/types.h>
                     31: #include <sys/stat.h>
                     32: #include <string.h>
                     33:
                     34: void
                     35: strmode(mode, p)
                     36:        mode_t mode;
                     37:        char *p;
                     38: {
                     39:         /* print type */
                     40:        switch (mode & S_IFMT) {
                     41:        case S_IFDIR:                   /* directory */
                     42:                *p++ = 'd';
                     43:                break;
                     44:        case S_IFCHR:                   /* character special */
                     45:                *p++ = 'c';
                     46:                break;
                     47:        case S_IFBLK:                   /* block special */
                     48:                *p++ = 'b';
                     49:                break;
                     50:        case S_IFREG:                   /* regular */
                     51:                *p++ = '-';
                     52:                break;
                     53:        case S_IFLNK:                   /* symbolic link */
                     54:                *p++ = 'l';
                     55:                break;
                     56:        case S_IFSOCK:                  /* socket */
                     57:                *p++ = 's';
                     58:                break;
                     59: #ifdef S_IFIFO
                     60:        case S_IFIFO:                   /* fifo */
                     61:                *p++ = 'p';
                     62:                break;
                     63: #endif
                     64: #ifdef S_IFWHT
                     65:        case S_IFWHT:                   /* whiteout */
                     66:                *p++ = 'w';
                     67:                break;
                     68: #endif
                     69:        default:                        /* unknown */
                     70:                *p++ = '?';
                     71:                break;
                     72:        }
                     73:        /* usr */
                     74:        if (mode & S_IRUSR)
                     75:                *p++ = 'r';
                     76:        else
                     77:                *p++ = '-';
                     78:        if (mode & S_IWUSR)
                     79:                *p++ = 'w';
                     80:        else
                     81:                *p++ = '-';
                     82:        switch (mode & (S_IXUSR | S_ISUID)) {
                     83:        case 0:
                     84:                *p++ = '-';
                     85:                break;
                     86:        case S_IXUSR:
                     87:                *p++ = 'x';
                     88:                break;
                     89:        case S_ISUID:
                     90:                *p++ = 'S';
                     91:                break;
                     92:        case S_IXUSR | S_ISUID:
                     93:                *p++ = 's';
                     94:                break;
                     95:        }
                     96:        /* group */
                     97:        if (mode & S_IRGRP)
                     98:                *p++ = 'r';
                     99:        else
                    100:                *p++ = '-';
                    101:        if (mode & S_IWGRP)
                    102:                *p++ = 'w';
                    103:        else
                    104:                *p++ = '-';
                    105:        switch (mode & (S_IXGRP | S_ISGID)) {
                    106:        case 0:
                    107:                *p++ = '-';
                    108:                break;
                    109:        case S_IXGRP:
                    110:                *p++ = 'x';
                    111:                break;
                    112:        case S_ISGID:
                    113:                *p++ = 'S';
                    114:                break;
                    115:        case S_IXGRP | S_ISGID:
                    116:                *p++ = 's';
                    117:                break;
                    118:        }
                    119:        /* other */
                    120:        if (mode & S_IROTH)
                    121:                *p++ = 'r';
                    122:        else
                    123:                *p++ = '-';
                    124:        if (mode & S_IWOTH)
                    125:                *p++ = 'w';
                    126:        else
                    127:                *p++ = '-';
                    128:        switch (mode & (S_IXOTH | S_ISVTX)) {
                    129:        case 0:
                    130:                *p++ = '-';
                    131:                break;
                    132:        case S_IXOTH:
                    133:                *p++ = 'x';
                    134:                break;
                    135:        case S_ISVTX:
                    136:                *p++ = 'T';
                    137:                break;
                    138:        case S_IXOTH | S_ISVTX:
                    139:                *p++ = 't';
                    140:                break;
                    141:        }
                    142:        *p++ = ' ';             /* will be a '+' if ACL's implemented */
                    143:        *p = '\0';
                    144: }

CVSweb