Add --totals option to size
[deliverable/binutils-gdb.git] / binutils / filemode.c
index 1bb5e64212001e6eadd30f60dff2376db9026cc7..7f9b1b76d4650b15641c6d5813e77b6a9188fd78 100644 (file)
@@ -1,9 +1,10 @@
 /* filemode.c -- make a string describing file modes
-   Copyright (C) 1985, 1990 Free Software Foundation, Inc.
+   Copyright 1985, 1990, 1991, 1994, 1995, 1997
+   Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 1, or (at your option)
+   the Free Software Foundation; either version 2, or (at your option)
    any later version.
 
    This program is distributed in the hope that it will be useful,
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.  */
 \f
-#include <sys/types.h>
-#include <sys/stat.h>
+#include "bfd.h"
+#include "bucomm.h"
 
-void mode_string ();
-static char ftypelet ();
-static void rwx ();
-static void setst ();
+static char ftypelet PARAMS ((unsigned long));
+static void setst PARAMS ((unsigned long, char *));
 
 /* filemodestring - fill in string STR with an ls-style ASCII
    representation of the st_mode field of file stats block STATP.
@@ -59,27 +59,80 @@ static void setst ();
        otherwise.
        'T' if the file is sticky but not executable. */
 
+#if 0
+
+/* This is not used; only mode_string is used.  */
+
 void
 filemodestring (statp, str)
      struct stat *statp;
      char *str;
 {
-  mode_string (statp->st_mode, str);
+  mode_string ((unsigned long) statp->st_mode, str);
 }
 
+#endif
+
+/* Get definitions for the file permission bits.  */
+
+#ifndef S_IRWXU
+#define S_IRWXU 0700
+#endif
+#ifndef S_IRUSR
+#define S_IRUSR 0400
+#endif
+#ifndef S_IWUSR
+#define S_IWUSR 0200
+#endif
+#ifndef S_IXUSR
+#define S_IXUSR 0100
+#endif
+
+#ifndef S_IRWXG
+#define S_IRWXG 0070
+#endif
+#ifndef S_IRGRP
+#define S_IRGRP 0040
+#endif
+#ifndef S_IWGRP
+#define S_IWGRP 0020
+#endif
+#ifndef S_IXGRP
+#define S_IXGRP 0010
+#endif
+
+#ifndef S_IRWXO
+#define S_IRWXO 0007
+#endif
+#ifndef S_IROTH
+#define S_IROTH 0004
+#endif
+#ifndef S_IWOTH
+#define S_IWOTH 0002
+#endif
+#ifndef S_IXOTH
+#define S_IXOTH 0001
+#endif
+
 /* Like filemodestring, but only the relevant part of the `struct stat'
    is given as an argument. */
 
 void
 mode_string (mode, str)
-     unsigned short mode;
+     unsigned long mode;
      char *str;
 {
-  str[0] = ftypelet (mode);
-  rwx ((mode & 0700) << 0, &str[1]);
-  rwx ((mode & 0070) << 3, &str[4]);
-  rwx ((mode & 0007) << 6, &str[7]);
-  setst (mode, str);
+  str[0] = ftypelet ((unsigned long) mode);
+  str[1] = (mode & S_IRUSR) != 0 ? 'r' : '-';
+  str[2] = (mode & S_IWUSR) != 0 ? 'w' : '-';
+  str[3] = (mode & S_IXUSR) != 0 ? 'x' : '-';
+  str[4] = (mode & S_IRGRP) != 0 ? 'r' : '-';
+  str[5] = (mode & S_IWGRP) != 0 ? 'w' : '-';
+  str[6] = (mode & S_IXGRP) != 0 ? 'x' : '-';
+  str[7] = (mode & S_IROTH) != 0 ? 'r' : '-';
+  str[8] = (mode & S_IWOTH) != 0 ? 'w' : '-';
+  str[9] = (mode & S_IXOTH) != 0 ? 'x' : '-';
+  setst ((unsigned long) mode, str);
 }
 
 /* Return a character indicating the type of file described by
@@ -93,61 +146,84 @@ mode_string (mode, str)
    'p' for fifos
    '-' for any other file type. */
 
+#ifndef S_ISDIR
+#ifdef S_IFDIR
+#define S_ISDIR(i) (((i) & S_IFMT) == S_IFDIR)
+#else /* ! defined (S_IFDIR) */
+#define S_ISDIR(i) (((i) & 0170000) == 040000)
+#endif /* ! defined (S_IFDIR) */
+#endif /* ! defined (S_ISDIR) */
+
+#ifndef S_ISBLK
+#ifdef S_IFBLK
+#define S_ISBLK(i) (((i) & S_IFMT) == S_IFBLK)
+#else /* ! defined (S_IFBLK) */
+#define S_ISBLK(i) 0
+#endif /* ! defined (S_IFBLK) */
+#endif /* ! defined (S_ISBLK) */
+
+#ifndef S_ISCHR
+#ifdef S_IFCHR
+#define S_ISCHR(i) (((i) & S_IFMT) == S_IFCHR)
+#else /* ! defined (S_IFCHR) */
+#define S_ISCHR(i) 0
+#endif /* ! defined (S_IFCHR) */
+#endif /* ! defined (S_ISCHR) */
+
+#ifndef S_ISFIFO
+#ifdef S_IFIFO
+#define S_ISFIFO(i) (((i) & S_IFMT) == S_IFIFO)
+#else /* ! defined (S_IFIFO) */
+#define S_ISFIFO(i) 0
+#endif /* ! defined (S_IFIFO) */
+#endif /* ! defined (S_ISFIFO) */
+
+#ifndef S_ISSOCK
+#ifdef S_IFSOCK
+#define S_ISSOCK(i) (((i) & S_IFMT) == S_IFSOCK)
+#else /* ! defined (S_IFSOCK) */
+#define S_ISSOCK(i) 0
+#endif /* ! defined (S_IFSOCK) */
+#endif /* ! defined (S_ISSOCK) */
+
+#ifndef S_ISLNK
+#ifdef S_IFLNK
+#define S_ISLNK(i) (((i) & S_IFMT) == S_IFLNK)
+#else /* ! defined (S_IFLNK) */
+#define S_ISLNK(i) 0
+#endif /* ! defined (S_IFLNK) */
+#endif /* ! defined (S_ISLNK) */
+
 static char
 ftypelet (bits)
-     unsigned short bits;
+     unsigned long bits;
 {
-  switch (bits & S_IFMT)
-    {
-    default:
-      return '-';
-    case S_IFDIR:
-      return 'd';
-#ifdef S_IFLNK
-    case S_IFLNK:
-      return 'l';
-#endif
-#ifdef S_IFCHR
-    case S_IFCHR:
-      return 'c';
-#endif
-#ifdef S_IFBLK
-    case S_IFBLK:
-      return 'b';
-#endif
+  if (S_ISDIR (bits))
+    return 'd';
+  if (S_ISLNK (bits))
+    return 'l';
+  if (S_ISBLK (bits))
+    return 'b';
+  if (S_ISCHR (bits))
+    return 'c';
+  if (S_ISSOCK (bits))
+    return 's';
+  if (S_ISFIFO (bits))
+    return 'p';
+
+#ifdef S_IFMT
 #ifdef S_IFMPC
-    case S_IFMPC:
-    case S_IFMPB:
-      return 'm';
-#endif
-#ifdef S_IFSOCK
-    case S_IFSOCK:
-      return 's';
-#endif
-#ifdef S_IFIFO
-#if S_IFIFO != S_IFSOCK
-    case S_IFIFO:
-      return 'p';
+  if ((bits & S_IFMT) == S_IFMPC
+      || (bits & S_IFMT) == S_IFMPB)
+    return 'm';
 #endif
+#ifdef S_IFNWK
+  if ((bits & S_IFMT) == S_IFNWK)
+    return 'n';
 #endif
-#ifdef S_IFNWK                 /* HP-UX */
-    case S_IFNWK:
-      return 'n';
 #endif
-    }
-}
-
-/* Look at read, write, and execute bits in BITS and set
-   flags in CHARS accordingly. */
 
-static void
-rwx (bits, chars)
-     unsigned short bits;
-     char *chars;
-{
-  chars[0] = (bits & S_IREAD) ? 'r' : '-';
-  chars[1] = (bits & S_IWRITE) ? 'w' : '-';
-  chars[2] = (bits & S_IEXEC) ? 'x' : '-';
+  return '-';
 }
 
 /* Set the 's' and 't' flags in file attributes string CHARS,
@@ -155,8 +231,8 @@ rwx (bits, chars)
 
 static void
 setst (bits, chars)
-     unsigned short bits;
-     char *chars;
+     unsigned long bits ATTRIBUTE_UNUSED;
+     char *chars ATTRIBUTE_UNUSED;
 {
 #ifdef S_ISUID
   if (bits & S_ISUID)
@@ -189,5 +265,3 @@ setst (bits, chars)
     }
 #endif
 }
-
-
This page took 0.026413 seconds and 4 git commands to generate.