Sponsored Content
Top Forums Programming Copy a file using UNIX-system calls Post 302300895 by c_d on Wednesday 25th of March 2009 10:17:50 AM
Old 03-25-2009
Quote:
Originally Posted by jim mcnamara
read returns 0 on EOF, -1 on error. EOF is not an error.
well in my textbook it says

Quote:
if successful, read() returns the number of bytes that it read, otherwise , it returns -1
so , should'nt it return -1 once it reaches the EOF and tries to read the next byte?

so , does it mean that even after the EOF is reached and it tries to read the next byte, it continues to "read" from the "stream"? eventhough there is nothing to read?

i guess i misunderstood this...
thanks,problem solved

Last edited by c_d; 03-25-2009 at 11:32 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

System Calls

What does the system call "dup" do? What is the difference between dup and dup2 I have a fair idea of what it does but I am confused when its coming down to the exact details... Please help me!:confused: (2 Replies)
Discussion started by: clickonline1
2 Replies

2. UNIX for Dummies Questions & Answers

System calls for cp and mv

Which system calls are made for operations cp and mv (2 Replies)
Discussion started by: gaurava99
2 Replies

3. UNIX for Dummies Questions & Answers

System calls?

open, creat, read, write, lseek and close Are they all primitive? :confused: *Another Question: is there a different between a system call, and an i/o system call? (2 Replies)
Discussion started by: PlunderBunny
2 Replies

4. Solaris

System calls ?

where can i find the differences in System calls between solaris and aix? also is it possible to find a comprehensive list of them? (1 Reply)
Discussion started by: TECHRAMESH
1 Replies

5. UNIX Desktop Questions & Answers

Using system calls

Hi, I'm new to UNIX system calls. Can someone share your knowledge as to how exactly system calls should be executed? Can they be typed like commands such as mkdir on the terminal itself? Also, are there any websites which will show me an example of the output to expect when a system call like... (1 Reply)
Discussion started by: ilavenil
1 Replies

6. UNIX for Dummies Questions & Answers

About system calls.

Hi all, I am new here . I want to know about system call in detail. As system calls are also function .How system identifies it.:) (2 Replies)
Discussion started by: vishwasrao
2 Replies

7. UNIX for Dummies Questions & Answers

system calls in C

Hello, how would i be able to call ps in C programming? thanks, ---------- Post updated at 01:39 AM ---------- Previous update was at 01:31 AM ---------- here's the complete system call, ps -o pid -p %d, getpit() (2 Replies)
Discussion started by: l flipboi l
2 Replies

8. UNIX for Dummies Questions & Answers

Unix directory system calls question

I'm currently studying for my exam, and is practicing with sample exam questions. However there is a question asking "Name THREE UNIX Directory system calls" and the answer given is "opendir, closedir and readdir", however the next question ask "Why is a write directory system call not included... (1 Reply)
Discussion started by: Izzy123
1 Replies

9. UNIX for Dummies Questions & Answers

How to Export Glance "Global System Calls" data to a file

Hello... I'm trying to setup a cronjob to record system data using glance at certain times of the day. My question is, how would one export the "Global System Calls" information to a file? Below is the command I have been using and it works to export CPU information. glance -f ... (0 Replies)
Discussion started by: fumus
0 Replies

10. UNIX for Dummies Questions & Answers

System calls in UNIX

Hi i am very new to programming in UNIX and don't understand the difference between a system call and a normal function call. Also can I implement system calls from within a program? If so could someone please give me an example of a system call from within a program. Lastly, when creating a... (1 Reply)
Discussion started by: bjhum33
1 Replies
getc(3S)																  getc(3S)

NAME
getc(), getc_unlocked(), getchar(), getchar_unlocked(), fgetc(), getw(), getw_unlocked() - get character or word from a stream file SYNOPSIS
Obsolescent Interface DESCRIPTION
Returns the next character (i.e., byte) from the named input stream, as an unsigned character converted to an integer. It also moves the file pointer, if defined, ahead one character in stream. is defined as and are defined both as macros and as functions. Same as but is a function rather than a macro. is slower than but it takes less space per invocation and its name can be passed as an argument to a function. returns the next word (i.e., in C) from the named input stream. increments the associated file pointer, if defined, to point to the next word. The size of a word is the size of an integer and varies from machine to machine. assumes no special alignment in the file. and are identical to and respectively except they do not perform any internal locking of the stream for multithreaded applications. Obsolescent Interface gets character or word from a stream file. APPLICATION USAGE
and interfaces should be used by multithread applications which have already used to acquire a mutual exclusion lock for the stream (see flockfile(3S)). After or is applied to a stream, the stream becomes byte-oriented (see orientation(5)). RETURN VALUE
Upon successful completion, and return the next byte from the input stream pointed to by stream for and If the stream is at end-of-file, the end-of-file indicator for the stream is set and EOF is returned. If a read error occurs, the error indicator for the stream is set, is set to indicate the error and EOF is returned. When the file corresponding to an open stream gets extended after the end-of-file is reached, any subsequent calls to these functions will succeed and the end-of-file indicator will remain set. However, in the UNIX2003 standards environment (see standards(5)), these functions will return EOF and the end-of-file indicator will still remain set. Upon successful completion, and return the next word from the input stream pointed to by stream. If the stream is at end-of-file, the end- of-file indicator for the stream is set and and return EOF. If a read error occurs, the error indicator for the stream is set, and and return EOF and set to indicate the error. and can be used to distinguish between an error condition and an end-of-file condition. ERRORS
and fail if data needs to be read into the stream's buffer, and: The flag is set for the file descriptor underlying stream and the process would be delayed in the read operation. The file descriptor underlying stream is not a valid file descriptor open for reading. The read operation was terminated due to the receipt of a signal, and either no data was transferred or the implementation does not report partial transfer for this file. A physical I/O error has occurred, or the process is a member of a background process and is attempting to read from its controlling terminal, and either the process is ignoring or blocking the signal or the process group of the process is orphaned. Additional values may be set by the underlying function (see read(2)). WARNINGS
and are implemented both as library functions and macros. The macro versions, which are used by default, are defined in To obtain the library function either use a to remove the macro definition or, if compiling in ANSI-C mode, enclose the function name in parenthesis or use the function address. The following example illustrates each of these methods : If the integer value returned by or is stored into a character variable then compared against the integer constant the comparison may never succeed because sign-extension of a character on widening to integer is machine-dependent. The macro version of incorrectly treats a stream argument with side effects. In particular, does not work sensibly. The function version of or should be used instead. Because of possible differences in word length and byte ordering, files written using are machine-dependent, and may be unreadable by on a different processor. Reentrant Interfaces If is defined before including the locked versions of the library functions for and are used by default. is an obsolescent interface supported only for compatibility with existing DCE applications. New multithreaded applications should use SEE ALSO
read(2), fclose(3S), ferror(3S), flockfile(3S), fopen(3S), fread(3S), gets(3S), putc(3S), scanf(3S), orientation(5), standards(5), thread_safety(5). STANDARDS CONFORMANCE
getc(3S)
All times are GMT -4. The time now is 12:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy