freebsd-ports/editors/bed/files/patch-shell.h
Greg Lewis be505ba5df . Fix the build on alpha by not assuming that you can cast a va_list
to a char **.  Instead, iterate the va_list and create the char **
  to pass to execvp.
. Don't allow -O3 to be hardwired into CFLAGS, just use what is set.  In
  particular, the 4.x/alpha system gcc produces many warnings about why
  using -O3 with it is bad.
. Bump PORTREVISION since although these fixes wre motivated to fix the
  alpha build, they have non-alpha implications too.

Submitted by:	bento
2004-01-30 21:19:15 +00:00

73 lines
1.7 KiB
C

$FreeBSD$
--- src/shell.h.orig Thu May 30 07:22:42 2002
+++ src/shell.h Fri Jan 30 12:22:26 2004
@@ -23,20 +23,56 @@
#else
#define process(commando,args...) executor(commando,commando,args,NULL)
#endif
-inline int executor(const char *commando,...) {
+inline int executor(char *commando,...) {
+ if(!fork()) {
va_list ap;
- if(!fork()) {
- va_start(ap,commando);
- execvp(commando,(char **)ap);
- va_end(ap);
- perror(commando);
- exit(4);
- }
- else {
- int statusdieprocessreturns;
- wait(&statusdieprocessreturns);
- return statusdieprocessreturns;
+ char *arg;
+ int argc = 0;
+ char **argv = NULL;
+ argv = (char **) malloc(2 * sizeof(char *)); /* commando, NULL */
+ if (argv == NULL)
+ goto cleanup;
+
+ /* Copy the relevant args into argv */
+ argv[argc] = (char *) malloc((strlen(commando) + 1) * sizeof(char));
+ if (argv[argc] == NULL)
+ goto cleanup;
+ strlcpy(argv[argc], commando, strlen(commando) + 1);
+
+ va_start(ap, commando);
+ while (*commando) {
+ switch (*commando++) {
+ case 's':
+ argc++;
+ if (realloc(argv, (argc + 2) * sizeof(char *)) == NULL)
+ goto cleanup;
+ arg = va_arg(ap, char *);
+ argv[argc] = (char *) malloc((strlen(arg) + 1) * sizeof(char));
+ if (argv[argc] == NULL)
+ goto cleanup;
+ strlcpy(argv[argc], arg, strlen(arg) + 1);
+ break;
+ }
+ }
+ va_end(ap);
+
+ argv[++argc] = NULL;
+ execvp(commando, argv);
+ perror(commando);
+cleanup:
+ if (argv != NULL) {
+ while (argc--) {
+ free(argv[argc]);
}
+ free(argv);
+ }
+ exit(4);
+ }
+ else {
+ int statusdieprocessreturns;
+ wait(&statusdieprocessreturns);
+ return statusdieprocessreturns;
}
+}
#endif
#endif