Sponsored Content
Top Forums Programming Cannot read a file with read(fd, buffer, buffersize) function Post 302324786 by achenle on Thursday 11th of June 2009 10:02:41 PM
Old 06-11-2009
You can't read from or write to a file descriptor after you close it. You need to remove the close() statements:

Code:
           .
           .
           .
          close (fRead);  <--- 
          if (fPadded =creat (argv[2], S_IRWXU) ==-1 )
          {
                    printf ("An error has occurred writing the file.\n");
                    return 0;
          }
          else
          {
             close (fPadded);   <---
               .
               .
               .

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Increase the buffer size to read lengthy lines

Hi All, I am trying to read output from a command. The output format is as follows: Thursday 13 Mar 2008 Information This is sample text Friday 14 Mar 2008 Warning This is one more sample text First line contains informtation (date etc) and the 2nd line contains some information. ... (3 Replies)
Discussion started by: ssunda6
3 Replies

2. Programming

read a file wich fscanf() in a function

I use fopen, fscanf, fclose to read a file. It can work well. since many files should be read, a function is created with the same code. But in the function, fscanf can not work well. for example, the first line of the the file is: > filename but the fscanf will give: 207/23/eee/34 it appears... (2 Replies)
Discussion started by: cdbug
2 Replies

3. Shell Programming and Scripting

Expect: How to read buffer for spawn

Hi All, I have to write one expect script to login to one system. I am using set timeout -1 match_max 100000 spawn ssh root@hostname Now when I do spawn ssh to that host it send some warning message and one challenge Challenge: 111-2345 I need to read this challenge value and has... (1 Reply)
Discussion started by: Lokesh Agrawal
1 Replies

4. Shell Programming and Scripting

Read Table,View,Package,Function and Procedure Name in a File

Hi I am new to Unix shell scripting. But i need help to slove the below issue. Issue description: I want to read table, view names and package names in a file my plan to find the table name is : search "From" key word find the table or view To find the packge name : Search "Package... (5 Replies)
Discussion started by: sboss
5 Replies

5. Programming

Maximum buffer size for read()

Hi friends, Hope everybody is fine. First have a look at my code, then we will talk about it. $ cat copy.c #include <stdio.h> #define PERMS 0644 /* RW for owner, R for group, others */ #define BUFSIZE 1 char *progname; int main(int argc,char * argv) { int f1, f2, n; ... (4 Replies)
Discussion started by: gabam
4 Replies

6. UNIX for Advanced & Expert Users

Input buffer and READ

Hello everyone, Can someone please explain the input buffer behaviour for the read command in ksh93 on AIX? I have 'googled' for weeks now, and did not find a satisfactory answer or solution to my dilemma. I have the following code: STTY=$(stty -g) if ;then stty -echo -icanon time 0 min... (1 Reply)
Discussion started by: gio001
1 Replies

7. Homework & Coursework Questions

C++ Attempting to modify this function to read from a (;) semi-colon-separated file

After some thought. I am uncomfortable issuing my professors name where, there may be unintended side effects from any negative responses/feedback. Willing to re post if I can omit school / professor publicly, but can message moderator for validation? I am here for knowledge and understanding,... (1 Reply)
Discussion started by: briandanielz
1 Replies

8. UNIX Desktop Questions & Answers

AIX how to read the file in function again and again

dear friends I have a wrote a shell script which works like this. 1.) a command is executed and the log is moved in the file. 2.) this file is copied in to the other file. 3.) used a grep command to find a particular word. 4.) if a particular word is there then the script will go to next... (4 Replies)
Discussion started by: aboy212u
4 Replies

9. Shell Programming and Scripting

[Bash] Read History function & Read Arrowkeys

Hi. How can I create a history function? (By "read" command or so) & How can I configure a read command so that the arrow keys are not displayed so funny? (^[[A) Thanks in advance. (4 Replies)
Discussion started by: sinnlosername
4 Replies

10. Ubuntu

Barcode scanner buffer read manipulation

Hello, I'm facing some problems with a barcode scanner from Cygnal Inc, model Sweda SL-20. Info from lsusb -v: Bus 003 Device 003: ID 10c4:ff11 Cygnal Integrated Products, Inc. Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 1.10 ... (4 Replies)
Discussion started by: minharojr
4 Replies
close(2)							System Calls Manual							  close(2)

NAME
close - Closes the file associated with a file descriptor SYNOPSIS
#include <unistd.h> int close ( int filedes ); PARAMETERS
Specifies a valid open file descriptor. STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: close(): XSH5.0, XNS5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. DESCRIPTION
The close() function closes the file associated with the filedes parameter. All regions of a file specified by the filedes parameter that this process has previously locked with the lockf() function are unlocked. This occurs even if the process still has the file open by another file descriptor. When all file descriptors associated with a pipe or FIFO special file have been closed, any data remaining in the pipe or FIFO is dis- carded. When all file descriptors associated with an open file descriptor are closed, the open file descriptor is freed. If the link count of the file is 0 (zero) when all file descriptors associated with the file have been closed, the space occupied by the file is freed and the file is no longer accessible. When the close() function needs to block, only the calling thread is suspended rather than all threads in the calling process. The last close() for a stream causes the stream associated with fildes to be dismantled. Dismantling includes popping any modules on the stream and closing the driver. If O_NDELAY and O_NONBLOCK are clear and there are no signals posted for the stream, close() waits up to 15 seconds for each module to drain and up to 15 seconds for each driver to drain. If the O_NDELAY or the O_NONBLOCK flag is set or if there are any pending signals, close() does not wait for output to drain, and dismantles the stream immediately. If a STREAMS file is closed, and the calling process had previously registered to receive a SIGPOLL signal [see signal()] for events associated with that file [see I_SETSIG in streamio(7)], the calling process is unregistered for events associated with the file. For sockets (fildes refers to a socket), a call to close causes the socket to be destroyed. For connection-oriented sockets that have the SOCK_LINGER option set and have untransmitted data, the close function blocks for the period of time specified by the linger interval until all data is transmitted. RETURN VALUES
Upon successful completion, a value of 0 (zero) is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. ERRORS
If the close() function fails, errno may be set to one of the following values: The filedes parameter is not a valid open file descriptor. The close() function was interrupted by a signal which was caught. A read or write physical I/O error. [Tru64 UNIX] fildes is on a remote machine and the link to that machine is no longer active. [Tru64 UNIX] A close() function on an NFS file system waits for all outstanding I/O to complete. If any operation completes with an error, the error will be returned by close(). The possible errors depend on the NFS server implementation, but the most likely errors are: The write has failed because the user's disk block quota is exhausted. Attempted to write a file that exceeds the maximum file size. A read or write physical I/O error. Attempted to write on a full file system. RELATED INFORMATION
Functions: exec(2), fcntl(2), lockf(3), open(2), pipe(2), socket(2), streamio(7). Standards: standards(5). delim off close(2)
All times are GMT -4. The time now is 03:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy