473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

are the functions in <stdio.h> system calls provided by operation system?

hi,guy
i have a question. are the functions in <stdio.h> system calls
provided by operation system?
if so, i want to know how C implements that we can call system calls by
using the functions in <stdio.h>.
i need your help, thanks a lot.

Apr 20 '06 #1
11 2738
Hello

stdio.h is a library, and so those call are _not_ system calls, they
are _library_ calls. Of course library calls are built on top of system
calls. Try this:

Step 1: save this as foo.c and compile with gcc foo.c

#include <stdio.h>

int
main ()
{
printf ("Hello comp.lang.c!\n");

return 0;
}

Step 2: run a.out and see this ($ is your prompt):
$ Hello comp.lang.c!
$

Step 3: run this command, and see:
$ strace a.out
execve("./a.out", ["a.out"], [/* 27 vars */]) = 0
uname({sys="Linux", node="linuxpoa3", ...}) = 0
brk(0) = 0x966e000
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or
directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=72077, ...}) = 0
old_mmap(NULL, 72077, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb75e7000
close(3) = 0
open("/lib/tls/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\2 00X\1"...,
512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1571692, ...}) = 0
old_mmap(NULL, 1275340, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) =
0x1f5000
old_mmap(0x327000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED,
3, 0x132000) = 0x327000
old_mmap(0x32a000, 9676, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x32a000
close(3) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0xb75e6000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb75e64e0,
limit:1048575, seg_32bit:1, contents:0, read_exec_only:0,
limit_in_pages:1, seg_not_present:0, useable:1}) = 0
munmap(0xb75e7000, 72077) = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb75f8000
write(1, "Hello comp.lang.c!\n", 19Hello comp.lang.c!
) = 19
munmap(0xb75f8000, 4096) = 0
exit_group(0) = ?

The above output is strace's output, or simply system call trace. Those
functions are system calls. As you can see, the actual action (print
the string) is performed by a system call:

write(1, "Hello comp.lang.c!\n", 19Hello comp.lang.c!) = 19

where 19 is the string length plus the '\0' on the end.

---mauricio

Apr 20 '06 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

pragma wrote:
Hello

stdio.h is a library,


Nope. Technically, stdio.h is the name of a standard include, which
/may/ be a real file containing C preprocessor and language constructs,
or may not. stdio.h is not a library, although the functions declared in
stdio.h /may/ be implemented in a library.

[snip]

- --

Lew Pitcher, IT Specialist, Corporate Technology Solutions,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFER+XwagVFX4UWr64RAny+AJ4kqMGX54v6WjuT11TcrQ 89HjKrjQCfTT4m
01MiZsre3OaazmXxHC+tAbA=
=Ebb5
-----END PGP SIGNATURE-----
Apr 20 '06 #3
"talk" <ji*******@gmail.com> writes:
i have a question. are the functions in <stdio.h> system calls
provided by operation system?
Maybe. The C standard says nothing about "system calls". The
functions declared in <stdio.h> can be implemented in any way the
implementation chooses.
if so, i want to know how C implements that we can call system calls by
using the functions in <stdio.h>.


The compiler generates code to implement the call. The details of how
this code works are entirely up to the implementer, as long as it
works as specified.

Why do you care?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 20 '06 #4
pragma wrote:
Hello

stdio.h is a library, and so those call are _not_ system calls, they
are _library_ calls. Of course library calls are built on top of system
calls. Try this:


There are systems that doesn't have "system calls".

C doesn't care wether what's specified in stdio.h ends up
in a library/system/something else call.
Apr 20 '06 #5
pragma wrote:
Hello
Please provide context when replying. Follow the link in my sig and read
the section especially for Google users.
stdio.h is a library, and so those call are _not_ system calls, they
are _library_ calls.
Do you know every single C implementation and OS in existence? How about
the ones that will be written next year? There is nothing in the C
standard that says an OS can't provide the C functions as a native part
of the OS in which can calling them will from a C program will be making
system calls.
Of course library calls are built on top of system
calls. Try this:

Step 1: save this as foo.c and compile with gcc foo.c

#include <stdio.h>

int
main ()
{
printf ("Hello comp.lang.c!\n");

return 0;
}

Step 2: run a.out and see this ($ is your prompt):
$ Hello comp.lang.c!
$

Step 3: run this command, and see:
$ strace a.out


There are systems with strace. The OP did not say which OS was being
used, so it could easily be one with no strace available.

<snip highly system specific stuff.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
Apr 20 '06 #6

"talk" <ji*******@gmail.com> wrote in message
news:11********************@i39g2000cwa.googlegrou ps.com...
hi,guy
i have a question. are the functions in <stdio.h> system calls
provided by operation system?
depends on the OS...
if so, i want to know how C implements that we can call system calls by
using the functions in <stdio.h>.
tis the other way round. The routines in stdio.h convert or map the standard
"C" interfaces onto the OS interfaces. For UNIX or LINUX they probably map
(almost) straight to system calls. For machines like the IBM.370 that have
record orientation system calls they have a lot of work to do. See if your
college has a copy of "The Standard C Library" by Plauger. Lots of info in
that....
i need your help, thanks a lot.

I think you need to do some research your self...
Apr 21 '06 #7
talk wrote:
i have a question. are the functions in <stdio.h> system calls
provided by operation system?


They are provide by the compiler vendor. The compiler vendor will
typically write library functions which implement these standard
compliant functions (plus possible extensions) on top of available OS
functionality. The contents of FILE, for example, is not dictated by
the OS, but rather the compiler vendor.

Your compiler will typically link the C runtime library, which contains
these functions, to your program when you build it. Your compiler may
or may not provide source code for this C runtime library, but if it
does this, looking through these sources might be very insightful for
you.

--
Paul Hsieh
http://www.pobox.com/~qed
http://bstring.sf.net/

Apr 21 '06 #8
we******@gmail.com writes:
talk wrote:
i have a question. are the functions in <stdio.h> system calls
provided by operation system?


They are provide by the compiler vendor.

[snip]

Not necessarily. They're provided as part of the C implementation,
but it's entirely possible for the compiler and library to be provided
by two different vendors. For example, gcc typically uses whatever
library is provided by the underlying system (though I think it does
something funky with headers).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 21 '06 #9
hi,
thank you for your advice.

i just want to know in DOS or in WindowsXp how a C program including
<stdio.h> outputs. for example, how do the function "printf()" in
<stdio.h> print a string in console in DOS or in WindowsXp.
can you give me some advices?
thanks.

Apr 21 '06 #10
talk wrote:
hi,
thank you for your advice.

i just want to know in DOS or in WindowsXp how a C program including
<stdio.h> outputs. for example, how do the function "printf()" in
<stdio.h> print a string in console in DOS or in WindowsXp.
By interpreting the format specifier and making whatever magic
incantations DOS or Windows XP require. How this occurs will be
different if you compile using Cygwin to how Visual Studio does it.
can you give me some advices?


My main advice is that you don't need to know how it works under the
hood. All you need to know is that it does what the C standard and the
implementations documentation specifies.

If you really do want to pursue this then go to a DOS or Windows group.
We don't deal with the specifics of implementations here since there are
so many implementations that one question about each once a month would
flood the group and make it unusable.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc
Apr 21 '06 #11

"talk" <ji*******@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
hi,
thank you for your advice.

i just want to know in DOS or in WindowsXp how a C program including
<stdio.h> outputs. for example, how do the function "printf()" in
<stdio.h> print a string in console in DOS or in WindowsXp.
can you give me some advices?
thanks.

As others have said that is implementation dependant. To write to a console
window it might call the "old" DOS I/O primitives, or it might use the
Windows I/O calls. Its been a long time since I looked but I think windows
provides both character mode and record/line mode functions. The implementor
of printf() is free to choose either..... You can download the source for
GCC and WATCOM. Why don't you do that and see how they work....
Apr 21 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
11
by: Scott Brady Drummonds | last post by:
Hi, everyone, I've checked a couple of on-line resources and am unable to determine how reinterpret_cast<> is different from static_cast<>. They both seem to perform a compile-time casting of...
1
by: | last post by:
Hi, Is there any good links for datatype interop? I need to pass some structure pointers into an unmanaged method and return char* etc but having some problems in my C++/CLI proxy class. I...
8
by: Mark | last post by:
We have a multi-line textbox that users copy and paste email text into. The pasted text frequently will contain a tag like <blah@aol.com> or similar. I believe .NET is protecting itself from code...
1
by: Michael Primeaux | last post by:
Why does the generic SortedList and generic SortedDictionary not define any virtual members? Thanks, Michael
5
by: Rainer Queck | last post by:
Hello NG, Is it possible to share the settings of an application with a class libreary? In my case I have a application and a set of different reports (home made) put into a class library. The...
4
by: Anastasios Hatzis | last post by:
I'm looking for a pattern where different client implementations can use the same commands of some fictive tool ("foo") by accessing some kind of API. Actually I have the need for such pattern for...
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.