src/lib/util.c
char *encode_mode(mode_t mode, char *buf)
{
  char *cp = buf;

  *cp++ = S_ISDIR(mode) ? 'd' : S_ISBLK(mode)  ? 'b' : S_ISCHR(mode)  ? 'c' :
          S_ISLNK(mode) ? 'l' : S_ISFIFO(mode) ? 'f' : S_ISSOCK(mode) ? 's' : '-';
  *cp++ = mode & S_IRUSR ? 'r' : '-';
  *cp++ = mode & S_IWUSR ? 'w' : '-';
  *cp++ = (mode & S_ISUID
               ? (mode & S_IXUSR ? 's' : 'S')
               : (mode & S_IXUSR ? 'x' : '-'));
  *cp++ = mode & S_IRGRP ? 'r' : '-';
  *cp++ = mode & S_IWGRP ? 'w' : '-';
  *cp++ = (mode & S_ISGID
               ? (mode & S_IXGRP ? 's' : 'S')
               : (mode & S_IXGRP ? 'x' : '-'));
  *cp++ = mode & S_IROTH ? 'r' : '-';
  *cp++ = mode & S_IWOTH ? 'w' : '-';
  *cp++ = (mode & S_ISVTX
               ? (mode & S_IXOTH ? 't' : 'T')
               : (mode & S_IXOTH ? 'x' : '-'));
  *cp = '\0';
  return cp;
}
/***********************************************************************
 * Encode the mode bits into a 10 character string like LS does
 ***********************************************************************/
Encode the mode bits into a 10 character string like LS does
Encode the mode bits into a 10 character string like LS does
char *encode_mode(mode_t mode, char *buf)
{
  char *cp = buf;
  *cp++ = S_ISDIR(mode) ? 'd' : S_ISBLK(mode)  ? 'b' : S_ISCHR(mode)  ? 'c' :
          S_ISLNK(mode) ? 'l' : S_ISFIFO(mode) ? 'f' : S_ISSOCK(mode) ? 's' : '-';
  *cp++ = mode & S_IRUSR ? 'r' : '-';
  *cp++ = mode & S_IWUSR ? 'w' : '-';
  *cp++ = (mode & S_ISUID
               ? (mode & S_IXUSR ? 's' : 'S')
               : (mode & S_IXUSR ? 'x' : '-'));
  *cp++ = mode & S_IRGRP ? 'r' : '-';
  *cp++ = mode & S_IWGRP ? 'w' : '-';
  *cp++ = (mode & S_ISGID
               ? (mode & S_IXGRP ? 's' : 'S')
               : (mode & S_IXGRP ? 'x' : '-'));
  *cp++ = mode & S_IROTH ? 'r' : '-';
  *cp++ = mode & S_IWOTH ? 'w' : '-';
  *cp++ = (mode & S_ISVTX
               ? (mode & S_IXOTH ? 't' : 'T')
               : (mode & S_IXOTH ? 'x' : '-'));
  *cp = '\0';
  return cp;
}
char * encode_mode ( mode_t mode , char * buf ) { char * cp = buf ; * cp ++ = S_ISDIR ( mode ) ? ' ' : S_ISBLK ( mode ) ? ' ' : S_ISCHR ( mode ) ? ' ' : S_ISLNK ( mode ) ? ' ' : S_ISFIFO ( mode ) ? ' ' : S_ISSOCK ( mode ) ? ' ' : ' ' ; * cp ++ = mode & S_IRUSR ? ' ' : ' ' ; * cp ++ = mode & S_IWUSR ? ' ' : ' ' ; * cp ++ = ( mode & S_ISUID ? ( mode & S_IXUSR ? ' ' : ' ' ) : ( mode & S_IXUSR ? ' ' : ' ' ) ) ; * cp ++ = mode & S_IRGRP ? ' ' : ' ' ; * cp ++ = mode & S_IWGRP ? ' ' : ' ' ; * cp ++ = ( mode & S_ISGID ? ( mode & S_IXGRP ? ' ' : ' ' ) : ( mode & S_IXGRP ? ' ' : ' ' ) ) ; * cp ++ = mode & S_IROTH ? ' ' : ' ' ; * cp ++ = mode & S_IWOTH ? ' ' : ' ' ; * cp ++ = ( mode & S_ISVTX ? ( mode & S_IXOTH ? ' ' : ' ' ) : ( mode & S_IXOTH ? ' ' : ' ' ) ) ; * cp = ' \0 ' ; return cp ; }
Encode the mode bits into a 10 character string like LS does
Encode the mode bits into a 10 character string like LS does