Last change
on this file since 1188 was 821, checked in by Bruno Cornec, 18 years ago |
Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)
|
File size:
691 bytes
|
Line | |
---|
1 | /*
|
---|
2 | * xreadlink.c - safe implementation of readlink.
|
---|
3 | * Returns a NULL on failure...
|
---|
4 | */
|
---|
5 |
|
---|
6 | #include <stdio.h>
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * NOTE: This function returns a malloced char* that you will have to free
|
---|
10 | * yourself. You have been warned.
|
---|
11 | */
|
---|
12 |
|
---|
13 | #include <unistd.h>
|
---|
14 | #include "libbb.h"
|
---|
15 |
|
---|
16 | char *xreadlink(const char *path)
|
---|
17 | {
|
---|
18 | enum { GROWBY = 80 }; /* how large we will grow strings by */
|
---|
19 |
|
---|
20 | char *buf = NULL;
|
---|
21 | int bufsize = 0, readsize = 0;
|
---|
22 |
|
---|
23 | do {
|
---|
24 | buf = xrealloc(buf, bufsize += GROWBY);
|
---|
25 | readsize = readlink(path, buf, bufsize); /* 1st try */
|
---|
26 | if (readsize == -1) {
|
---|
27 | bb_perror_msg("%s", path);
|
---|
28 | free(buf);
|
---|
29 | return NULL;
|
---|
30 | }
|
---|
31 | }
|
---|
32 | while (bufsize < readsize + 1);
|
---|
33 |
|
---|
34 | buf[readsize] = '\0';
|
---|
35 |
|
---|
36 | return buf;
|
---|
37 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.