File: instshow.c

package info (click to toggle)
cvm 0.11-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 492 kB
  • ctags: 215
  • sloc: ansic: 1,777; makefile: 48; sh: 12
file content (94 lines) | stat: -rw-r--r-- 2,211 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "installer.h"

#define DENTRY_SLOTS 16
static const char* dentries[DENTRY_SLOTS] = {0};
static int last_dentry = 0;

static void showmode(char type, unsigned mode)
{
  putchar(type);
  putchar((mode & 0400) ? 'r' : '-');
  putchar((mode & 0200) ? 'w' : '-');
  putchar((mode & 0100) ?
	  (mode & 04000) ? 's' : 'x' :
	  (mode & 04000) ? 'S' : '-');
  putchar((mode & 040) ? 'r' : '-');
  putchar((mode & 020) ? 'w' : '-');
  putchar((mode & 010) ?
	  (mode & 02000) ? 's' : 'x' :
	  (mode & 02000) ? 'S' : '-');
  putchar((mode & 04) ? 'r' : '-');
  putchar((mode & 02) ? 'w' : '-');
  putchar((mode & 01) ?
	  (mode & 01000) ? 't' : 'x' :
	  (mode & 01000) ? 'T' : '-');
}

static void show(char type, int dir, const char* filename,
		 unsigned uid, unsigned gid, unsigned mode)
{
  showmode(type, mode);

  if (uid == (unsigned)-1) fputs("      N/A", stdout);
  else printf(" %8d", uid);
  if (gid == (unsigned)-1) fputs("      N/A", stdout);
  else printf(" %8d", gid);

  putchar(' ');
  fputs(dentries[dir], stdout);
  putchar('/');
  puts(filename);
}

void c(int dir, const char* filename,
       unsigned uid, unsigned gid, unsigned mode)
{
  show('-', dir, filename, uid, gid, mode);
}

int d(int dir, const char* subdir,
      unsigned uid, unsigned gid, unsigned mode)
{
  show('d', dir, subdir, uid, gid, mode);
  return opensubdir(dir, subdir);
}

int opendir(const char* dir)
{
  if (last_dentry >= DENTRY_SLOTS) {
    fputs("instshow: error: Too many open directories!\n", stderr);
    exit(1);
  }
  dentries[last_dentry] = strdup(dir);
  return last_dentry++;
}

int opensubdir(int dir, const char* subdir)
{
  char* str;
  if (last_dentry >= DENTRY_SLOTS) {
    fputs("instshow: error: Too many open directories!\n", stderr);
    exit(1);
  }
  str = malloc(strlen(dentries[dir])+1+strlen(subdir)+1);
  strcpy(str, dentries[dir]);
  strcat(str, "/");
  strcat(str, subdir);
  dentries[last_dentry] = str;
  return last_dentry++;
}

int main(void)
{
  puts(" type/mode    owner    group path");
  insthier();
  return 0;
}