Re: [PATCH/WIP 1/8] wrapper: implement xopen()

2015-06-04 Thread Paul Tan
On Thu, May 28, 2015 at 3:03 AM, Torsten Bögershausen wrote: > On 2015-05-27 15.33, Paul Tan wrote: >> +/** >> + * xopen() is the same as open(), but it die()s if the open() fails. >> + */ >> +int xopen(const char *path, int flags, mode_t mode) >> +{ >> + int fd; >> + >> + assert(path); >>

Re: [PATCH/WIP 1/8] wrapper: implement xopen()

2015-06-03 Thread Paul Tan
On Thu, May 28, 2015 at 5:53 AM, Jeff King wrote: > On Wed, May 27, 2015 at 09:03:47PM +0200, Torsten Bögershausen wrote: > >> The original open can take 2 or 3 parameters, how about this: >> int xopen(const char *path, int oflag, ... ) >> { >> va_list params; >> int mode; >>

Re: [PATCH/WIP 1/8] wrapper: implement xopen()

2015-05-27 Thread Jeff King
On Wed, May 27, 2015 at 09:03:47PM +0200, Torsten Bögershausen wrote: > The original open can take 2 or 3 parameters, how about this: > int xopen(const char *path, int oflag, ... ) > { > va_list params; > int mode; > int fd; > > va_start(params, oflag); > m

Re: [PATCH/WIP 1/8] wrapper: implement xopen()

2015-05-27 Thread Torsten Bögershausen
On 2015-05-27 15.33, Paul Tan wrote: > A common usage pattern of open() is to check if it was successful, and > die() if it was not: > > int fd = open(path, O_WRONLY | O_CREAT, 0777); > if (fd < 0) > die_errno(_("Could not open '%s' for writing."), path); > > Implement a

Re: [PATCH/WIP 1/8] wrapper: implement xopen()

2015-05-27 Thread Stefan Beller
On Wed, May 27, 2015 at 6:33 AM, Paul Tan wrote: > A common usage pattern of open() is to check if it was successful, and > die() if it was not: > > int fd = open(path, O_WRONLY | O_CREAT, 0777); > if (fd < 0) > die_errno(_("Could not open '%s' for writing."), path)

[PATCH/WIP 1/8] wrapper: implement xopen()

2015-05-27 Thread Paul Tan
A common usage pattern of open() is to check if it was successful, and die() if it was not: int fd = open(path, O_WRONLY | O_CREAT, 0777); if (fd < 0) die_errno(_("Could not open '%s' for writing."), path); Implement a wrapper function xopen() that does the above s