Sponsored Content
Full Discussion: ANSI C vs POSIX
Top Forums Programming ANSI C vs POSIX Post 31249 by Vishnu on Monday 4th of November 2002 08:32:49 PM
Old 11-04-2002
System calls (open, creat, unlink, read etc) as the name suggests are calls to the system - in case of UNIX system, the UNIX kernel...

Part of the kernel consists of a collection of low level procedures through which processes can access resources. These procedures are called system calls and they are the primary means for a program to interact with other parts of the system. System calls are listed in section 2 of the manual pages. Any time that a program wishes to do anything beyond its own process environment, it must use system calls...

Many programs use (and must use sometimes) system calls... you can see what system calls are made by a common UNIX program using "trace" command (strace on linux), eg. "trace ls"..

since system calls are the only way to "talk" to the kernel, even the library functions doing system interactions also have to use them.. the purpose of library functions is two fold...

- Because they form the lowest level of interaction, system calls are very simplistic and generic. It would be very tedious to have to write all of your programs using only system calls. Thus procedures and functions (like fopen) for the most common tasks have already been written and stored in libraries - for example fopen() for open(), scanf(), getchar() for read().

- system calls are platform / implementation specific, also you are not assured to find the same naming for system calls on all platforms... but the ANSI standard library functions assure you to have the same functional interface on every platform - UNIX or otherwise...

Cheers!
Vishnu.
 

10 More Discussions You Might Find Interesting

1. Programming

K&R vs. ANSI

To anyone that can answer this: Are the differences great between the ANSI and K&R standard? What are some of the major differences between them?? -REM (1 Reply)
Discussion started by: REM
1 Replies

2. Programming

Ansi C

Dear All, I have to develope some C functions in Unix for a Magic program. The original MSE code which compiles the attached C program uses a +z option, but the cc compiler don't know this. The complete command in the compiler script is 'cc -c -Aa +z myfile.c'. The warning message is 'The -z... (4 Replies)
Discussion started by: Frankie
4 Replies

3. HP-UX

ansi problem

Hi! Can anyone help me with the problem i am having. Im new to hpux and i am trying to set up the programs i use. One such program is the irc client BitchX, ive ran it on several pc/sun boxes with no problems. On my c360 with an fx6 card and a eizo f56 17in monitor (1024x768 85hz vesa) the ansi... (0 Replies)
Discussion started by: Lewis
0 Replies

4. HP-UX

ANSI / C Compiler for HP-UX 11.11

Good Day I downloaded Server Evaluation copy of C/ANSI compiler, but when I try to compile a file with it, it gives me following error - (for HP-UX 11.11 v1 PA-RISC) Internal Error: Codeword file /opt/ansic/newconfig/ansic.cwd missing or empty. Detailed Errors are as follows Internal... (3 Replies)
Discussion started by: shawnbishop
3 Replies

5. Programming

hint on ansi c

I am a student. And need help on following program. I want to make a c program. I have to scan a sentence and I have to interchange a word from that sentence. Example: Scan the sentence is " Drilling machine and Milling machine " . Replace the word "machine" by "operation". And output should... (2 Replies)
Discussion started by: dhaval chevli
2 Replies

6. Shell Programming and Scripting

Convert file from Unix - ANSI to PC - ANSI

Hi, I am creating a file in Unix using a shell script. The file is getting created in the Unix - ANSI format. My requirement is to convert it to the PC - ANSI format. Can anyone tell me how to do this? Thanks, Sunil (0 Replies)
Discussion started by: ssmallya
0 Replies

7. HP-UX

Unix_ANSI to PC-ANSI

I want to convert a file from Unix-ANSI to PC-ANSI format. How can i achieve that? (0 Replies)
Discussion started by: ssmallya
0 Replies

8. HP-UX

HP-UX ansi c precompiler

Hi, How can i find which ansi c precompiler are installed on my hp-ux b11.23 itanuim machine ? Thanks (3 Replies)
Discussion started by: yoavbe
3 Replies

9. Programming

why the implementatoin of Bakery algorithm in ANSI C does not work in ANSI C

I follow the description of wiki (Lamport's bakery algorithm - Wikipedia, the free encyclopedia), then implement that algorithm in C, but it doesn't work, Starving is still here, is the implementation worry? Only print out: Thread ID: 0 START! Thread ID: 0 END! Thread ID: 0 START!... (2 Replies)
Discussion started by: sehang
2 Replies

10. Programming

C fdopen with and without -ansi

I have very little experience with gcc compilation under different environments, so please bear with me. I carried over 20 years old project into Ubuntu 18.04, it has old style K&R parameters, no function declarations to speak of, many functions without return are not declared void, and on and... (8 Replies)
Discussion started by: migurus
8 Replies
FOPEN(3)						     Linux Programmer's Manual							  FOPEN(3)

NAME
fopen, fdopen, freopen - stream open functions SYNOPSIS
#include <stdio.h> FILE *fopen(const char *path, const char *mode); FILE *fdopen(int fildes, const char *mode); FILE *freopen(const char *path, const char *mode, FILE *stream); DESCRIPTION
The fopen function opens the file whose name is the string pointed to by path and associates a stream with it. The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.): r Open text file for reading. The stream is positioned at the beginning of the file. r+ Open for reading and writing. The stream is positioned at the beginning of the file. w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file. a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file. The mode string can also include the letter ``b'' either as a last character or as a character between the characters in any of the two- character strings described above. This is strictly for compatibility with ANSI X3.159-1989 (``ANSI C'') and has no effect; the ``b'' is ignored on all POSIX conforming systems, including Linux. (Other systems may treat text files and binary files differently, and adding the ``b'' may be a good idea if you do I/O to a binary file and expect that your program may be ported to non-Unix environments.) Any created files will have mode S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH (0666), as modified by the process' umask value (see umask(2)). Reads and writes may be intermixed on read/write streams in any order. Note that ANSI C requires that a file positioning function inter- vene between output and input, unless an input operation encounters end-of-file. (If this condition is not met, then a read is allowed to return the result of writes other than the most recent.) Therefore it is good practice (and indeed sometimes necessary under Linux) to put an fseek or fgetpos operation between write and read operations on such a stream. This operation may be an apparent no-op (as in fseek(..., 0L, SEEK_CUR) called for its synchronizing side effect. Opening a file in append mode (a as the first character of mode) causes all subsequent write operations to this stream to occur at end-of- file, as if preceded by an fseek(stream,0,SEEK_END); call. The fdopen function associates a stream with the existing file descriptor, fildes. The mode of the stream (one of the values "r", "r+", "w", "w+", "a", "a+") must be compatible with the mode of the file descriptor. The file position indicator of the new stream is set to that belonging to fildes, and the error and end-of-file indicators are cleared. Modes "w" or "w+" do not cause truncation of the file. The file descriptor is not dup'ed, and will be closed when the stream created by fdopen is closed. The result of applying fdopen to a shared memory object is undefined. The freopen function opens the file whose name is the string pointed to by path and associates the stream pointed to by stream with it. The original stream (if it exists) is closed. The mode argument is used just as in the fopen function. The primary use of the freopen function is to change the file associated with a standard text stream (stderr, stdin, or stdout). RETURN VALUE
Upon successful completion fopen, fdopen and freopen return a FILE pointer. Otherwise, NULL is returned and the global variable errno is set to indicate the error. ERRORS
EINVAL The mode provided to fopen, fdopen, or freopen was invalid. The fopen, fdopen and freopen functions may also fail and set errno for any of the errors specified for the routine malloc(3). The fopen function may also fail and set errno for any of the errors specified for the routine open(2). The fdopen function may also fail and set errno for any of the errors specified for the routine fcntl(2). The freopen function may also fail and set errno for any of the errors specified for the routines open(2), fclose(3) and fflush(3). CONFORMING TO
The fopen and freopen functions conform to ANSI X3.159-1989 (``ANSI C''). The fdopen function conforms to IEEE Std1003.1-1988 (``POSIX.1''). SEE ALSO
open(2), fclose(3), fileno(3) BSD MANPAGE
2002-01-03 FOPEN(3)
All times are GMT -4. The time now is 08:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy