Prex Home / Browse Source - Prex Version: 0.9.0

root/usr/lib/libc/string/strmode.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. strmode

   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 #include <unistd.h>
  34 
  35 void
  36 strmode(mode, p)
  37         mode_t mode;
  38         char *p;
  39 {
  40          /* print type */
  41         switch (mode & S_IFMT) {
  42         case S_IFDIR:                   /* directory */
  43                 *p++ = 'd';
  44                 break;
  45         case S_IFCHR:                   /* character special */
  46                 *p++ = 'c';
  47                 break;
  48         case S_IFBLK:                   /* block special */
  49                 *p++ = 'b';
  50                 break;
  51         case S_IFREG:                   /* regular */
  52                 *p++ = '-';
  53                 break;
  54         case S_IFLNK:                   /* symbolic link */
  55                 *p++ = 'l';
  56                 break;
  57         case S_IFSOCK:                  /* socket */
  58                 *p++ = 's';
  59                 break;
  60 #ifdef S_IFIFO
  61         case S_IFIFO:                   /* fifo */
  62                 *p++ = 'p';
  63                 break;
  64 #endif
  65 #ifdef S_IFWHT
  66         case S_IFWHT:                   /* whiteout */
  67                 *p++ = 'w';
  68                 break;
  69 #endif
  70         default:                        /* unknown */
  71                 *p++ = '?';
  72                 break;
  73         }
  74         /* usr */
  75         if (mode & S_IRUSR)
  76                 *p++ = 'r';
  77         else
  78                 *p++ = '-';
  79         if (mode & S_IWUSR)
  80                 *p++ = 'w';
  81         else
  82                 *p++ = '-';
  83         switch (mode & (S_IXUSR | S_ISUID)) {
  84         case 0:
  85                 *p++ = '-';
  86                 break;
  87         case S_IXUSR:
  88                 *p++ = 'x';
  89                 break;
  90         case S_ISUID:
  91                 *p++ = 'S';
  92                 break;
  93         case S_IXUSR | S_ISUID:
  94                 *p++ = 's';
  95                 break;
  96         }
  97         /* group */
  98         if (mode & S_IRGRP)
  99                 *p++ = 'r';
 100         else
 101                 *p++ = '-';
 102         if (mode & S_IWGRP)
 103                 *p++ = 'w';
 104         else
 105                 *p++ = '-';
 106         switch (mode & (S_IXGRP | S_ISGID)) {
 107         case 0:
 108                 *p++ = '-';
 109                 break;
 110         case S_IXGRP:
 111                 *p++ = 'x';
 112                 break;
 113         case S_ISGID:
 114                 *p++ = 'S';
 115                 break;
 116         case S_IXGRP | S_ISGID:
 117                 *p++ = 's';
 118                 break;
 119         }
 120         /* other */
 121         if (mode & S_IROTH)
 122                 *p++ = 'r';
 123         else
 124                 *p++ = '-';
 125         if (mode & S_IWOTH)
 126                 *p++ = 'w';
 127         else
 128                 *p++ = '-';
 129         switch (mode & (S_IXOTH | S_ISVTX)) {
 130         case 0:
 131                 *p++ = '-';
 132                 break;
 133         case S_IXOTH:
 134                 *p++ = 'x';
 135                 break;
 136         case S_ISVTX:
 137                 *p++ = 'T';
 138                 break;
 139         case S_IXOTH | S_ISVTX:
 140                 *p++ = 't';
 141                 break;
 142         }
 143         *p++ = ' ';             /* will be a '+' if ACL's implemented */
 144         *p = '\0';
 145 }

/* [<][>][^][v][top][bottom][index][help] */