linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "J." <mailing-lists@xs4all.nl>
To: linux-c-programming@vger.kernel.org
Subject: getlogin(), prints ((NULL)) when printing multiple times in a row.
Date: Wed, 12 Mar 2003 23:49:26 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.21.0303122335180.15008-100000@hestia> (raw)
In-Reply-To: <Pine.LNX.4.33.0303051227480.30291-100000@soochak.ncst.ernet.in>

Hello,

I have ran into undefined behaviour. Not from my girl-friend this time,
but from my C program. (It's not that time of month, yet... :()

But, Everytime when I execute the following C code (bottom) from within a
shell loop as in:

while : ; do ./program ; done

it prints: ((NULL))

But when I excute it in the normal way:
./program
It prints perfectly ok: myusername

C Code.
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int main(void) {
 char *username = NULL;

 username = getlogin();
 /* for(;;) */
  printf("%s\n", username);

 return 0;
}

When I call the printf from a for loop in the native C code it also
starts to print ((NULL)) after a couple of loops.

I am writing a network program that gives a lot of status output when
working verbose. It doesn't look very good ((NULL)) everytime when the
output is above average.

Anyone ?

Thnkx 

J.


  parent reply	other threads:[~2003-03-12 22:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-05  7:02 structure size Mohammed Khalid Ansari
2003-03-05  8:27 ` Helmut Djurkin
2003-03-25 10:00   ` strange SIGSEGV Alexi Jordanov
2003-03-05  9:06 ` (F)structure size Steven Smith
2003-03-12 22:49 ` J. [this message]
2003-03-12 23:14   ` getlogin(), prints ((NULL)) when printing multiple times in a row Glynn Clements
2003-03-13  0:18     ` getlogin(), prints ((NULL)) solved.. thnkx.. glen J.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.21.0303122335180.15008-100000@hestia \
    --to=mailing-lists@xs4all.nl \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).