Re: Alternative for getline() function in AIX 5.3
On Wed, Jul 28, 2010, Etzion Bar-Noy wrote about "Re: Alternative for getline() function in AIX 5.3": > IBM supply a set of GNU utilities, including GCC-related software (and GCC, > as well, if I recall correctly, but an old one) in an additional CD supplied > with AIX. This is called something around "Utilities for Linux" or some > other lie. So you do not need to force gcc to compile under AIX, but only > use it. > Same goes, probably, for many additional libraries. I didn't check, but it is quite likely that while they supply gcc and many other GNU utilities, they do not have glibc. While glibc's getline() is trivial to port to AIX, much of glibc is very closely related to the kernel's APIs, so it varies a lot from kernel to kernel. Last time I checked, glibc was only available for Linux. But needless to say, parts of glibc (like the aforementioned geline()) should have no trouble to compile on AIX. -- Nadav Har'El| Wednesday, Jul 28 2010, 17 Av 5770 n...@math.technion.ac.il |- Phone +972-523-790466, ICQ 13349191 |Does replacing myself with a shell-script http://nadav.harel.org.il |make me impressive or insignificant? ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Alternative for getline() function in AIX 5.3
IBM supply a set of GNU utilities, including GCC-related software (and GCC, as well, if I recall correctly, but an old one) in an additional CD supplied with AIX. This is called something around "Utilities for Linux" or some other lie. So you do not need to force gcc to compile under AIX, but only use it. Same goes, probably, for many additional libraries. P.S - they install in RPM format :-) Ez On Tue, Jul 27, 2010 at 11:32 PM, Oleg Goldshmidt wrote: > Omer Zak 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 | p...@goldshmidt.org > > ___ > Linux-il mailing list > Linux-il@cs.huji.ac.il > http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il > ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Alternative for getline() function in AIX 5.3
Omer Zak 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 | p...@goldshmidt.org ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Alternative for getline() function in AIX 5.3
What I mean is to use whatever preprocessor symbol that is defined when building using gcc, but undefined on AIX; or vice versa. On Tue, 2010-07-27 at 21:53 +0300, Oleg Goldshmidt wrote: > Omer Zak writes: > > > #ifdef __GNUC__ > > // use getline() > > #else /* __GNUC__ */ > > // use gets() or fgets() > > #endif /* __GNUC__ */ > > I am not sure what you meant here, Omer, but IIRC __GNUC__ means > gcc-specific code, and the OP does not have gcc on AIX. I am probably > missing something... Nor does AIX have _GNU_SOURCE, I believe. > > I'd say if you wrote your code with fgets() forget about getline(). -- Bottom posters are filthy heretics and infidels and ought to be burned on the stake after having been tarred, feathered and having rotten eggs thrown at their faces! My own blog is at http://www.zak.co.il/tddpirate/ My opinions, as expressed in this E-mail message, are mine alone. They do not represent the official policy of any organization with which I may be affiliated in any way. WARNING TO SPAMMERS: at http://www.zak.co.il/spamwarning.html ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Alternative for getline() function in AIX 5.3
Omer Zak writes: > #ifdef __GNUC__ > // use getline() > #else /* __GNUC__ */ > // use gets() or fgets() > #endif /* __GNUC__ */ I am not sure what you meant here, Omer, but IIRC __GNUC__ means gcc-specific code, and the OP does not have gcc on AIX. I am probably missing something... Nor does AIX have _GNU_SOURCE, I believe. I'd say if you wrote your code with fgets() forget about getline(). -- Oleg Goldshmidt | p...@goldshmidt.org ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Alternative for getline() function in AIX 5.3
"Nadav Har'El" writes: > The second alternative is to make use of the wonderful fact that > Linux is free software, and just take the source code of getline() > and incorporate it in your program! I can't imagine that getline() > is more than a couple of dozen lines - it's not that > complicated... In fact, you can probably easily write one > yourself... It may be possible, but maybe not as simple as finding the function's code and pasting it into an AIX app. Getline is a part of glibc, which is licensed under LGPL. This means that you can use it as a library and link your application to it using an API without releasing the app under LGPL, but I doubt you can use the code in a single application without releasing it under LGPL or GPL (unless all the code is in a header, which I doubt). IANAL, and I didn't look too deeply, but this is what LGPL seems to say. The procedure would be to determine which pieces of glibc would together be enough to provide getline functionality in a library, and then either try to compile it on AIX (which may or may not work, depending on how much gcc-specific stuff there is) or cross-compile the thing with gcc for AIX, taking care that the interface is not GNU-specific and that none of the stuff needed to compile and link clashes with the libc of AIX. Then deliver the resulting library as a part of your overall AIX package, and then take care of actual production / legal / support / operations stuff (e.g., what is the procedure for delivering the code of the resulting library on request?) that a commercial company needs to deal with, unlike folks who just upload code to sourceforge or something. (I am not saying it is impossible, I am saying it is a serious issue beyond coding that requires involvement of many functions in an organization). It may or may not be simple... Or simpler than fgets, which is what matters. Disclaimer: I have not tried this and encountered difficulties, I am just trying to imagine what the potential issues may be. -- Oleg Goldshmidt | p...@goldshmidt.org ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Alternative for getline() function in AIX 5.3
On Tue, 2010-07-27 at 14:02 +0300, Nadav Har'El wrote: > On Tue, Jul 27, 2010, Israel Shikler wrote about "Alternative for getline() > function in AIX 5.3": > > I am looking for an alternative to getline(), that would be portable to both > > Linux and AIX. [... snipped ...] > The second alternative is to make use of the wonderful fact that Linux is > free software, and just take the source code of getline() and incorporate > it in your program! I can't imagine that getline() is more than a couple > of dozen lines - it's not that complicated... In fact, you can probably > easily write one yourself... ... that is, if Shikler has access to a lawyer familiar with LGPLv2.1 who can certify that his application's license and terms of usage are compatible with LGPLv2.1 (the license of stdio.h). Things may even be more complicated than this. --- Omer -- MS-Windows is the Pal-Kal of the PC world. My own blog is at http://www.zak.co.il/tddpirate/ My opinions, as expressed in this E-mail message, are mine alone. They do not represent the official policy of any organization with which I may be affiliated in any way. WARNING TO SPAMMERS: at http://www.zak.co.il/spamwarning.html ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Alternative for getline() function in AIX 5.3
DISCLAIMER: 1. I don't have access to AIX. 2. I didn't actually test my suggestions. Alternatives: 1. Use fgets() if it is available for AIX, too. 2. According to man getline, getline() is a GNU extension, and is available only when you #define _GNU_SOURCE. So use: #ifdef __GNUC__ // use getline() #else /* __GNUC__ */ // use gets() or fgets() #endif /* __GNUC__ */ 3. Same as (2) but test __USE_POSIX instead of __GNUC__ On Tue, 2010-07-27 at 13:15 +0300, Israel Shikler wrote: > Hi, > > I have a C program that reads one line of text from the keyboard. > > The original program was written 10 years ago and was compiled with cc > on AIX 4.x. > I used the gets() function which was the only option available at the > time. > > Recently, I had to port the program to gcc on Linux, but I was > confronted with lots of segfaults. > So, I had to change the function to getline() which is much more > stable and secure. > > However, I was asked to maintain the new version on AIX 5.3 as well. > > When recompiling the program on the AIX machine I was confronted with > the lack of getline() in AIX implementation of cc. > I do not have gcc on that machine, and installing it would be an > option of last resort . > > I am looking for an alternative to getline(), that would be portable > to both Linux and AIX. -- "Kosher" Cellphones (cellphones with blocked SMS, video and Internet) are menace to the deaf. They must be outlawed! (See also: http://www.zak.co.il/tddpirate/2006/04/21/the-grave-danger-to-the-deaf-from-kosher-cellphones/ and http://www.zak.co.il/tddpirate/2007/02/04/rabbi-eliashiv-declared-war-on-the-deaf/) My own blog is at http://www.zak.co.il/tddpirate/ My opinions, as expressed in this E-mail message, are mine alone. They do not represent the official policy of any organization with which I may be affiliated in any way. WARNING TO SPAMMERS: at http://www.zak.co.il/spamwarning.html ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Alternative for getline() function in AIX 5.3
On Tuesday 27 Jul 2010 13:15:13 Israel Shikler wrote: > Hi, > > I have a C program that reads one line of text from the keyboard. > > The original program was written 10 years ago and was compiled with cc on > AIX 4.x. > I used the gets() function which was the only option available at the time. > > Recently, I had to port the program to gcc on Linux, but I was confronted > with lots of segfaults. > So, I had to change the function to getline() which is much more stable and > secure. > > However, I was asked to maintain the new version on AIX 5.3 as well. > > When recompiling the program on the AIX machine I was confronted with the > lack of getline() in AIX implementation of cc. > I do not have gcc on that machine, and installing it would be an option of > last resort . > > I am looking for an alternative to getline(), that would be portable to > both Linux and AIX. > Will fgets be OK enough? http://www.opengroup.org/onlinepubs/009695399/functions/fgets.html Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ Funny Anti-Terrorism Story - http://shlom.in/enemy God considered inflicting XSLT as the tenth plague of Egypt, but then decided against it because he thought it would be too evil. Please reply to list if it's a mailing list post - http://shlom.in/reply . ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Alternative for getline() function in AIX 5.3
On Tue, Jul 27, 2010, Israel Shikler wrote about "Alternative for getline() function in AIX 5.3": > I am looking for an alternative to getline(), that would be portable to both > Linux and AIX. The first obvious alternative is to use fgets(). fgets(), unlike gets(), is secure because you give it the buffer's length. Nobody should EVER use gets(), but fgets() is perfectly fine (unless I'm missing something). The second alternative is to make use of the wonderful fact that Linux is free software, and just take the source code of getline() and incorporate it in your program! I can't imagine that getline() is more than a couple of dozen lines - it's not that complicated... In fact, you can probably easily write one yourself... Nadav. -- Nadav Har'El| Tuesday, Jul 27 2010, 16 Av 5770 n...@math.technion.ac.il |- Phone +972-523-790466, ICQ 13349191 |If I am not for myself, who will be for http://nadav.harel.org.il |me? If I am only for myself, who am I? ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Alternative for getline() function in AIX 5.3
Hi, I have a C program that reads one line of text from the keyboard. The original program was written 10 years ago and was compiled with cc on AIX 4.x. I used the gets() function which was the only option available at the time. Recently, I had to port the program to gcc on Linux, but I was confronted with lots of segfaults. So, I had to change the function to getline() which is much more stable and secure. However, I was asked to maintain the new version on AIX 5.3 as well. When recompiling the program on the AIX machine I was confronted with the lack of getline() in AIX implementation of cc. I do not have gcc on that machine, and installing it would be an option of last resort . I am looking for an alternative to getline(), that would be portable to both Linux and AIX. Please advise. Thanks. Israel Shikler ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il