"Fossies" - the Fresh Open Source Software Archive

Member "di-4.47.2/C/di.c" (30 Oct 2019, 3530 Bytes) of package /linux/privat/di-4.47.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "di.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 4.45_vs_4.46.

    1 /*
    2  * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA
    3  */
    4 
    5 /*
    6  * di.c
    7  *
    8  *  Warning: Do not replace your system's 'df' command with this program.
    9  *           You will in all likelihood break your installation procedures.
   10  *
   11  *  Display sizes:
   12  *      512 - posix (512 bytes)
   13  *      k - kilobytes
   14  *      m - megabytes
   15  *      g - gigabytes
   16  *      t - terabytes
   17  *      P - petabytes
   18  *      E - exabytes
   19  *      h - "human readable" scaled alternative 1
   20  *      H - "human readable" scaled alternative 2
   21  *
   22  *  Sort types:
   23  *      N - name (default)
   24  *      n - none (mount order)
   25  *      s - special
   26  *      a - avail
   27  *      t - type
   28  *      r - reverse sort
   29  *
   30  *  Format string values:
   31  *      m - mount point
   32  *      M - mount point, full length
   33  *      b - total kbytes
   34  *      B - total kbytes available for use by the user.
   35  *             [ (tot - (free - avail)) ]
   36  *      u - kbytes used (actual number of kbytes used) [ (tot - free) ]
   37  *      c - calculated number of kbytes used [ (tot - avail) ]
   38  *      f - kbytes free
   39  *      v - kbytes available
   40  *      p - percentage not available for use.
   41  *          (space not available for use / total disk space)
   42  *             [ (tot - avail) / tot ]
   43  *      1 - percentage used.
   44  *          (actual space used / total disk space)
   45  *             [ (tot - free) / tot ]
   46  *      2 - percentage of user-available space in use (bsd style).
   47  *          Note that values over 100% are possible.
   48  *          (actual space used / disk space available to user)
   49  *             [ (tot - free) / (tot - (free - avail)) ]
   50  *      i - total i-nodes (files)
   51  *      U - used i-nodes
   52  *      F - free i-nodes
   53  *      P - percent i-nodes used     [ (tot - avail) / tot ]
   54  *      s - filesystem name (special)
   55  *      S - filesystem name (special), full length
   56  *      t - disk partition type
   57  *      T - disk partition type (full length)
   58  *      I - mount time
   59  *      O - mount options.
   60  *
   61  *  System V.4 `/usr/bin/df -v` Has format: msbuf1
   62  *  System V.4 `/usr/bin/df -k` Has format: sbcvpm
   63  *  System V.4 `/usr/ucb/df`    Has format: sbuv2m
   64  *
   65  *  The default format string for this program is: smbuvpT
   66  *
   67  *  Environment variables:
   68  *      DI_ARGS:            specifies any arguments to di.
   69  *      POSIXLY_CORRECT:    forces posix mode.
   70  *      BLOCKSIZE:          BSD df block size.
   71  *      DF_BLOCK_SIZE:      GNU df block size.
   72  *
   73  *  Note that for filesystems that do not have, or systems (SysV.3)
   74  *  that do not report, available space, the amount of available space is
   75  *  set to the free space.
   76  *
   77  */
   78 
   79 #include "config.h"
   80 #include "dimain.h"
   81 #include "di.h"
   82 
   83 #if _hdr_stdio
   84 # include <stdio.h>
   85 #endif
   86 #if _hdr_stdlib
   87 # include <stdlib.h>
   88 #endif
   89 #if _sys_types \
   90     && ! defined (DI_INC_SYS_TYPES_H) /* xenix */
   91 # define DI_INC_SYS_TYPES_H
   92 # include <sys/types.h>
   93 #endif
   94 #if _use_mcheck
   95 # include <mcheck.h>
   96 #endif
   97 
   98 /* end of system specific includes/configurations */
   99 
  100 int
  101 #if _proto_stdc
  102 main (int argc, const char * argv [])
  103 #else
  104 main (argc, argv)
  105     int         argc;
  106     const char  * argv [];
  107 #endif
  108 {
  109   char      *disp;
  110   diData_t  diData;
  111 
  112 #if _use_mcheck
  113   mcheck_pedantic (NULL);
  114   mtrace ();
  115 #endif
  116 
  117   disp = dimainproc (argc, argv, 0, &diData);
  118   if (diData.options.exitFlag == DI_EXIT_FAIL) {
  119     exit (2);
  120   }
  121   if (diData.options.exitFlag == DI_EXIT_WARN) {
  122     exit (1);
  123   }
  124   if (diData.options.exitFlag == DI_EXIT_OK) {
  125     exit (0);
  126   }
  127   if (disp != (char *) NULL) {
  128     fputs (disp, stdout);
  129     free (disp);
  130   }
  131   cleanup (&diData);
  132   return 0;
  133 }