summaryrefslogtreecommitdiffstats
path: root/sys-utils/readprofile.c
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:25:49 +0100
committerKarel Zak2006-12-07 00:25:49 +0100
commite8f2641919de90b488ce3788a7795b88311750b5 (patch)
tree68f3732da38ff1b21ec49780d7c830250329fec9 /sys-utils/readprofile.c
parentImported from util-linux-2.11f tarball. (diff)
downloadkernel-qcow2-util-linux-e8f2641919de90b488ce3788a7795b88311750b5.tar.gz
kernel-qcow2-util-linux-e8f2641919de90b488ce3788a7795b88311750b5.tar.xz
kernel-qcow2-util-linux-e8f2641919de90b488ce3788a7795b88311750b5.zip
Imported from util-linux-2.11m tarball.
Diffstat (limited to 'sys-utils/readprofile.c')
-rw-r--r--sys-utils/readprofile.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/sys-utils/readprofile.c b/sys-utils/readprofile.c
index eee8634fe..117a53072 100644
--- a/sys-utils/readprofile.c
+++ b/sys-utils/readprofile.c
@@ -64,16 +64,36 @@ usage(void) {
exit(1);
}
+static void *
+xmalloc (size_t size) {
+ void *t;
+
+ if (size == 0)
+ return NULL;
+
+ t = malloc (size);
+ if (t == NULL) {
+ fprintf(stderr, _("out of memory"));
+ exit(1);
+ }
+
+ return t;
+}
+
static FILE *
myopen(char *name, char *mode, int *flag) {
- static char cmdline[S_LEN];
+ int len = strlen(name);
- if (!strcmp(name+strlen(name)-3,".gz")) {
- *flag=1;
- sprintf(cmdline,"zcat %s", name);
- return popen(cmdline,mode);
+ if (!strcmp(name+len-3,".gz")) {
+ FILE *res;
+ char *cmdline = xmalloc(len+6);
+ sprintf(cmdline, "zcat %s", name);
+ res = popen(cmdline,mode);
+ free(cmdline);
+ *flag = 1;
+ return res;
}
- *flag=0;
+ *flag = 0;
return fopen(name,mode);
}