473,614 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2759
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="Lin ux", 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_IFRE G|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\200X\1"...,
512) = 512
fstat64(3, {st_mode=S_IFRE G|0755, st_size=1571692 , ...}) = 0
old_mmap(NULL, 1275340, PROT_READ|PROT_ EXEC, MAP_PRIVATE, 3, 0) =
0x1f5000
old_mmap(0x3270 00, 12288, PROT_READ|PROT_ WRITE, MAP_PRIVATE|MAP _FIXED,
3, 0x132000) = 0x327000
old_mmap(0x32a0 00, 9676, PROT_READ|PROT_ WRITE,
MAP_PRIVATE|MAP _FIXED|MAP_ANON YMOUS, -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:0xb75 e64e0,
limit:1048575, seg_32bit:1, contents:0, read_exec_only: 0,
limit_in_pages: 1, seg_not_present :0, useable:1}) = 0
munmap(0xb75e70 00, 72077) = 0
fstat64(1, {st_mode=S_IFCH R|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(0xb75f80 00, 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+XwagV FX4UWr64RAny+AJ 4kqMGX54v6WjuT1 1TcrQ89HjKrjQCf TT4m
01MiZsre3OaazmX xHC+tAbA=
=Ebb5
-----END PGP SIGNATURE-----
Apr 20 '06 #3
"talk" <ji*******@gmai l.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_Keit h) 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*******@gmai l.com> wrote in message
news:11******** ************@i3 9g2000cwa.googl egroups.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_Keit h) 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

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

Similar topics

2
3208
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 writing one object in C# which will take the entire table tag contents and renders. Ie., we need to pass "<table>………… <thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
2
10554
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 type="text/javascript"> <!]> </script> <script type="text/javascript"
11
5135
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 one type to another. However, I'm certain that there is something else that is happening. Can someone explain the difference or recommend an online site that can explain it to me?
1
4673
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 have a methods with signitures like the following... unsigned char someMethod(unsigned char blah, SOMESTRUCT* somestruct);
8
1635
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 injection by throwing a global error when this occurs. The exception message is pasted below. We will NOT be able to train our users to eliminate all <> tags. What's the best way to deal with this issue? Thanks in advance.
1
4707
by: Michael Primeaux | last post by:
Why does the generic SortedList and generic SortedDictionary not define any virtual members? Thanks, Michael
5
8605
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 plan is to delivere different report.dlls with the main app. But it is essentially importent, that the reports and the app use the same settings.
4
2372
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 my own tool (http://openswarm.sourceforge.net). I already started restructuring my code to separate the actual command implementations from the command-line scripts (which is optparser-based now) and have some ideas how to proceed. But probably...
3
3366
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, &gt ,&ltCompany&gt to display '<', '>' and '<Company>' respectively. But is there any freeware code available which could implement the above functionality without having to use &gt,&lt and such stuff???
0
8176
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8620
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8571
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8265
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8423
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5537
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4048
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
1420
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.