* [Fwd: Re: printf without '\n']
@ 2005-10-25 15:49 Gerardo García Peña
0 siblings, 0 replies; only message in thread
From: Gerardo García Peña @ 2005-10-25 15:49 UTC (permalink / raw)
To: linux-assembly
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: Re: printf without '\n' --]
[-- Type: message/rfc822, Size: 1752 bytes --]
From: "Gerardo García Peña" <gerardo@kung-foo.dhs.org>
To: Ricardo Catalinas Jimenez <th1nk3r@server01.org>
Subject: Re: printf without '\n'
Date: Tue, 25 Oct 2005 17:45:19 +0200
Message-ID: <435E530F.5020004@kung-foo.dhs.org>
Ricardo Catalinas Jimenez wrote:
>Newbie simple question:
>
>With a code like this:
>
>.section .data
>MSG:
> .ascii "Hello\0"
>.section .text
> .globl _start
>_start:
> pushl %ebp
> movl %esp, %ebp
>
> pushl $MSG
> call printf
>
> movl %ebp, %esp
> popl %ebp
>
> movl $1, %eax
> xorl %ebx, %ebx
> int $0x80
>
>I compiled it with:
>as code.s -o code.o; ld --dynamic-linker /lib/ld-linux.so.2 -lc \
> test.o -o test
>
>With that ascii string, nothing is printed but when I use "Hello\n\0" it
>works fine.
>
>What is the reason for not printing the string if there isn't a '\n' in
>it?
>
>I something related with the buffered (by lines) IO?
>
>Why with a C program it does not happend.
>
>Thanks in advance.
>
>
>
You should flush stdio(3) buffers before exiting. Try with fflush(3).
This program exits with the _exit(2) system call without flushing
buffers nor deinitializing C standard libraries.
If you try to exit with exit(3) libc it will work.
You can the behaviour of your current program with this simple C program:
main()
{
printf("hello");
_exit(0);
}
If you change _exit(2) by exit(3) it will work...
Luck,
Gerardo García Peña
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-10-25 15:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-25 15:49 [Fwd: Re: printf without '\n'] Gerardo García Peña
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).