Date: Tue, 25 Jun 2002 02:37:18 -0700 From: Alfred Perlstein <bright@mu.org> To: Mark Murray <mark@grondar.za> Cc: Jonathan Belson <jon@witchspace.com>, current@freebsd.org Subject: Re: Perl scripts that need rewiting - Any volunteers? Message-ID: <20020625093717.GM53232@elvis.mu.org> In-Reply-To: <200206250920.g5P9KJnG005006@grimreaper.grondar.org> References: <3D17770E.1060904@witchspace.com> <200206250920.g5P9KJnG005006@grimreaper.grondar.org>
next in thread | previous in thread | raw e-mail | index | archive | help
* Mark Murray <mark@grondar.za> [020625 02:26] wrote: > > > I couldn't see a simple way around this, any clues? > > How's this? > > int handle; > template = "/tmp/mumbleXXXXXXXX"; > char *cmd; > handle = mkstemp(template); // template is modified > asprintf(cmd, "prog > %s", template); > system(cmd); > close(handle); // bye-bye file Kinda buggy. :) int fd, status; char *template = strdup("/tmp/mumbleXXXXXXXX"); if (template == NULL) /* ERROR */ fd = mkstemp(template); if (fd == -1) { free(template); /* ERROR */ } asprintf(cmd, "prog > %s", template); status = system(cmd); unlink(template); free(cmd); free(template); close(fd); /* if normal exit, return true if exit code was 0 (success) */ return (WIFEXITED(status) ? WEXITSTATUS(status) == EXIT_SUCCESS : 0); -- -Alfred Perlstein [alfred@freebsd.org] 'Instead of asking why a piece of software is using "1970s technology," start asking why software is ignoring 30 years of accumulated wisdom.' Tax deductible donations for FreeBSD: http://www.freebsdfoundation.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020625093717.GM53232>