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

« back to all changes in this revision

Viewing changes to src/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
#include "rlinetd.h"
 
10
 
 
11
int rl_readfile(char *path, void **addr, int *len) {
 
12
        int fd;
 
13
        struct stat st;
 
14
        void *tmp;
 
15
        
 
16
        if((fd = open(path, O_RDONLY)) < 0) {
 
17
                rl_warn(_("Failed to open %s (%s)"), path, strerror(errno));
 
18
                return -1;
 
19
        }
 
20
        if(fstat(fd, &st)) {
 
21
                rl_warn(_("Failed to fstat %d (%s)"), fd, strerror(errno));
 
22
                close(fd);
 
23
                return -1;
 
24
        }
 
25
        tmp = malloc(st.st_size);
 
26
        if (!tmp)
 
27
                rl_fatal(EX_SOFTWARE, _("ABORT - Can't allocate memory"));
 
28
        if(read(fd, tmp, st.st_size) < 0) {
 
29
                rl_warn(_("Failed to inhale file %s"), path);
 
30
                free(tmp);
 
31
                close(fd);
 
32
                return -1;
 
33
        }
 
34
        close(fd);
 
35
        *addr = tmp;
 
36
        *len = st.st_size;
 
37
        return 0;
 
38
}
 
39
 
 
40
/* vim: set ts=2: */