Browse Source

tools-source: fix gcc-4.7 support by handling return values properly

stable/0.6
Alejandro Mery 11 years ago
committed by Alejandro Mery
parent
commit
646cba76b6
3 changed files with 67 additions and 23 deletions
  1. +42
    -9
      src/tools-source/cmd_wrapper.c
  2. +13
    -7
      src/tools-source/getdu.c
  3. +12
    -7
      src/tools-source/getfiles.c

+ 42
- 9
src/tools-source/cmd_wrapper.c

@ -1,18 +1,19 @@
/*
* --- T2-COPYRIGHT-NOTE-BEGIN ---
* --- SDE-COPYRIGHT-NOTE-BEGIN ---
* This copyright note is auto-generated by ./scripts/Create-CopyPatch.
*
* T2 SDE: misc/tools-source/cmd_wrapper.c
*
* Filename: src/tools-source/cmd_wrapper.c
* Copyright (C) 2013 The OpenSDE Project
* Copyright (C) 2004 - 2006 The T2 SDE Project
* Copyright (C) 1998 - 2003 Clifford Wolf
*
*
* More information can be found in the files COPYING and README.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License. A copy of the
* GNU General Public License can be found in the file COPYING.
* --- T2-COPYRIGHT-NOTE-END ---
* --- SDE-COPYRIGHT-NOTE-END ---
*
* Generic command wrapper.
*
@ -58,6 +59,38 @@
#define VERBOSE_DEBUG 1
int debug=1;
static inline ssize_t write2(int fd, const char *buf, size_t count)
{
int wc, wt = 0;
while (count > 0) {
wc = write(fd, buf, count);
if (wc > 0) {
wt += wc;
count -= count;
buf += wc;
} else if (wc < 0 && errno != EINTR) {
fprintf(stderr, "cmd_wrapper: write(%d): %s.\n", fd, strerror(errno));
return wc;
}
}
return wt;
}
static inline ssize_t read2(int fd, char *buf, size_t count)
{
ssize_t rc;
read_retry:
rc = read(fd, buf, count);
if (rc < 0) {
if (errno == EINTR)
goto read_retry;
else
fprintf(stderr, "cmd_wrapper: read(%d): %s.\n", fd, strerror(errno));
}
return rc;
}
/*
* Clean config vars before using them
*/
@ -373,8 +406,8 @@ int main(int argc, char ** argv) {
/* Create content of input file */
for (c3=0; c3<c1; c3++) {
write(infd, newargv[c3], strlen(newargv[c3]));
write(infd, "\n", 1);
write2(infd, newargv[c3], strlen(newargv[c3]));
write2(infd, "\n", 1);
}
lseek(infd, 0, SEEK_SET);
@ -397,7 +430,7 @@ int main(int argc, char ** argv) {
size_t argvsize = lseek(outfd, 0, SEEK_END);
char* argvmem = malloc (argvsize + 1); /* might not have trailing \n */
lseek(outfd, 0, SEEK_SET);
read(outfd, argvmem, argvsize);
read2(outfd, argvmem, argvsize);
int newargc = 64; /* initial newargv size */
newargv = malloc( sizeof(char*) * newargc );

+ 13
- 7
src/tools-source/getdu.c

@ -1,21 +1,24 @@
/*
* --- T2-COPYRIGHT-NOTE-BEGIN ---
* --- SDE-COPYRIGHT-NOTE-BEGIN ---
* This copyright note is auto-generated by ./scripts/Create-CopyPatch.
*
* T2 SDE: misc/tools-source/getdu.c
*
* Filename: src/tools-source/getdu.c
* Copyright (C) 2013 The OpenSDE Project
* Copyright (C) 2004 - 2006 The T2 SDE Project
* Copyright (C) 1998 - 2003 Clifford Wolf
*
*
* More information can be found in the files COPYING and README.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License. A copy of the
* GNU General Public License can be found in the file COPYING.
* --- T2-COPYRIGHT-NOTE-END ---
* --- SDE-COPYRIGHT-NOTE-END ---
*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
@ -23,7 +26,10 @@ int main(int argc, char ** argv) {
int size=0;
char fn[512];
struct stat st;
if (argc > 1) chdir(argv[1]);
if (argc > 1 && chdir(argv[1]) < 0) {
fprintf(stderr, "getdu: %s: %s.\n", argv[1], strerror(errno));
return 1;
}
while ( scanf("%*s %s",fn) == 1 ) {
if ( lstat(fn,&st) ) continue;
if ( S_ISREG(st.st_mode) ) size+=st.st_size;

+ 12
- 7
src/tools-source/getfiles.c

@ -1,20 +1,22 @@
/*
* --- T2-COPYRIGHT-NOTE-BEGIN ---
* --- SDE-COPYRIGHT-NOTE-BEGIN ---
* This copyright note is auto-generated by ./scripts/Create-CopyPatch.
*
* T2 SDE: misc/tools-source/getfiles.c
*
* Filename: src/tools-source/getfiles.c
* Copyright (C) 2013 The OpenSDE Project
* Copyright (C) 2004 - 2006 The T2 SDE Project
* Copyright (C) 1998 - 2003 Clifford Wolf
*
*
* More information can be found in the files COPYING and README.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License. A copy of the
* GNU General Public License can be found in the file COPYING.
* --- T2-COPYRIGHT-NOTE-END ---
* --- SDE-COPYRIGHT-NOTE-END ---
*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
@ -23,7 +25,10 @@
int main(int argc, char ** argv) {
char *fn, buf[512], *n;
struct stat st;
if (argc > 1) chdir(argv[1]);
if (argc > 1 && chdir(argv[1]) < 0) {
fprintf(stderr, "getfiles: %s: %s.\n", argv[1], strerror(errno));
return 1;
}
while ( fgets(buf, 512, stdin) != NULL &&
(fn = strchr(buf, ' ')) != NULL ) {
if ( (n = strchr(++fn, '\n')) != NULL ) *n = '\0';

Loading…
Cancel
Save