~ubuntu-branches/debian/sid/rlinetd/sid

« back to all changes in this revision

Viewing changes to util.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2010-03-20 18:03:45 UTC
  • mfrom: (2.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100320180345-x1srfbe2tg00ezsf
Tags: 0.7-1
* New upstream version.
* Recommend rsyslog instead of sysklogd (closes: #526922).
* update-inetd:
  + add support for enabling, disabling and removing entries;
  + use ucf for managing generated files;
  + ignore ucf files in rlinetd.conf;
  + make appropriate changes in  postinst and postrm scripts.
* Set debhelper compat level to 7
* Standards-Version: 3.8.4 (no changes). 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <sys/types.h>
2
 
#include <sys/stat.h>
3
 
#include <fcntl.h>
4
 
#include <unistd.h>
5
 
#include <stdlib.h>
6
 
 
7
 
#include "error.h"
8
 
#include "util.h"
9
 
 
10
 
int rl_readfile(char *path, void **addr, int *len) {
11
 
        int fd;
12
 
        struct stat st;
13
 
        void *tmp;
14
 
        
15
 
        if((fd = open(path, O_RDONLY)) < 0) {
16
 
                rl_warn("Failed to open %s (%s)", path, strerror(errno));
17
 
                return -1;
18
 
        }
19
 
        if(fstat(fd, &st)) {
20
 
                rl_warn("Failed to fstat %d (%s)", fd, strerror(errno));
21
 
                close(fd);
22
 
                return -1;
23
 
        }
24
 
        tmp = malloc(st.st_size);
25
 
        if (!tmp)
26
 
                rl_fatal(EX_SOFTWARE, "ABORT - Can't allocate memory");
27
 
        if(read(fd, tmp, st.st_size) < 0) {
28
 
                rl_warn("Failed to inhale file %s", path);
29
 
                free(tmp);
30
 
                close(fd);
31
 
                return -1;
32
 
        }
33
 
        close(fd);
34
 
        *addr = tmp;
35
 
        *len = st.st_size;
36
 
        return 0;
37
 
}
38
 
 
39
 
/* vim: set ts=2: */