[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: memstat-0.9 hurd patch (PATH_MAX)



On Tue, Jan 24, 2012 at 10:58:34AM +0100, Tanguy LE CARROUR wrote:
> > On Tue, Jan 24, 2012 at 09:46:16AM +0100, Tanguy LE CARROUR wrote:
> > > I hope I've fixed all the bugs in my patch, but I have one last small
> > > question: Do I really need to check if BUFSIZ is defined?
> >
> > Yes, as it's a macro usually defined in libc headers.
> >
> "Usually"?!

It may even be forced by POSIX, I didn't look. Keep portability in mind
when coding, as other systems may simply not look a lot like your usual
Linux distro (we Hurd people know that better than many).

> > #define FORMAT "/proc/%d/maps"
> > #define BUFF_SIZE (sizeof(FORMAT) + (sizeof(int) * 3)) /* sizeof() already
> > includes the terminating \0 */
> >
> > buff = malloc(BUFF_SIZE);
> >
> > if (buff == NULL)
> >        handle_error();
> >
> > sprintf(buff, FORMAT, pid);
> >
> > #undef FORMAT
> > #undef BUFF_SIZE
> >
> Looks better, thanks.

Hm, now that I read that, I'm wondering why you need dynamic allocation
for that case ? It seems to me you could use the stack.

-- 
Richard Braun


Reply to: