File: ministat.c

package info (click to toggle)
bcron 0.11-8
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 728 kB
  • sloc: sh: 3,099; ansic: 2,416; makefile: 28
file content (50 lines) | stat: -rw-r--r-- 999 bytes parent folder | download | duplicates (4)
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
#include <bglibs/sysdeps.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>

#include <bglibs/msg.h>
#include <bglibs/wrap.h>
#include <bglibs/str.h>

#include "bcron.h"

static void copystat(struct ministat* m, const struct stat* s)
{
  memset(m, 0, sizeof *m);
  m->exists = 1;
  m->device = s->st_dev;
  m->inode = s->st_ino;
  m->mode = s->st_mode;
  m->size = s->st_size;
  m->mtime = s->st_mtime;
}

void minifstat(int fd, struct ministat* s)
{
  struct stat st;
  if (fstat(fd, &st) != 0)
    die1sys(111, "Could not fstat");
  else
    copystat(s, &st);
}

void ministat(const char* path, struct ministat* s)
{
  struct stat st;
  if (stat(path, &st) != 0) {
    if (errno == ENOENT)
      memset(s, 0, sizeof *s);
    else
      die3sys(111, "Could not stat '", path, "'");
  }
  else
    copystat(s, &st);
}

void ministat2(const char* base, const char* entry, struct ministat* s)
{
  static str path;
  wrap_str(str_copy3s(&path, base, "/", entry));
  ministat(path.s, s);
}