Alternative for getline() function in AIX 5.3

Alternative for getline() function in AIX 5.3

Oleg Goldshmidt pub at goldshmidt.org
Tue Jul 27 23:32:31 IDT 2010


Omer Zak <w1 at zak.co.il> writes:

> What I mean is to use whatever preprocessor symbol that is defined when
> building using gcc, but undefined on AIX; or vice versa.

I see. I suspect you may need both __GNUC__ and _GNU_SOURCE to be
defined for getline() to work in the context though: the first will
react to compilation with gcc and the second will include the right
bits from glibc. I have not checked, but it is not clear to me if one
implies the other, I suspect not.

In any case, the explicit requirement is that the resulting program
should be portable (at least between Liux and AIX), and, I suppose,
the fact that gets() is insecure should be an additional
consideration. 

Yet another consideration is that newer incarnaions of POSIX removed
gets() from requirements, AFAIK, neither Linux nor AIX actually ripped
it out yet, but it may happen in the future (on Linux sooner than on
AIX).

So, between

1. develop a non-portable Linux/gcc branch based on getline() and
   choose at compile time with the preprocessor (keeping AIX insecure
   with the existing, gets()-based code),

2. develop a getline() branch for Linux and rewrite AIX with the
   secure fgets(),

3. develop a portable and secure fgets()-based implementation for both
   AIX and Linux,

I'd vote for door #3.

There is option 4 suggested by Nadav (rip getline() from glibc and use
on AIX). Depending on circumstances, it may be fairly easy or
completely unfeasible (it is, no doubt, feasible technically, it may
be unfeasible operatonally) or anything in between.

-- 
Oleg Goldshmidt | pub at goldshmidt.org



More information about the Linux-il mailing list