Questions tagged [fclose]

fclose closes an open file resource, releasing it from memory and any write-locks on the file.

fclose closes an open file resource, releasing it from memory and any write-locks on the file.

It is a matching function for fopen, after read and writes have been completed. This function will release any write-locks on the file. While often unimportant for batch processes (when a process ends, write-locks are automatically released), it becomes important to release unused resources for long-running applications or background processes.

278 questions
3
votes
1 answer

How to close a socket() if I used fdopen() on the socket descriptor

If I create a socket sockfd = socket(...); and then I associate it to a FILE stream by calling FILE* f=fdopen(sockfd,"r+"); Should I call both close(sockfd); and fclose(f); or only close(sockfd);? What happens to the FILE structure if I call or…
kanito73
  • 87
  • 4
3
votes
0 answers

Closing a C++ FILE pointer which uses a file descriptor from Java

When using a file descriptor in native code, which has been obtained from a ParcelFileDescriptor, should the native side use fclose after an fdopen? The documentation states that the ParcelaleFileDescriptor instance owns the file descriptor, and it…
PerracoLabs
  • 16,449
  • 15
  • 74
  • 127
3
votes
1 answer

Rewriting some code using fsockopen to use curl instead

My host doesn't allow fsockopen, but it does allow curl. I'm happy using curl from the cli, but haven't had to use it with PHP much. How do I write this using curl instead? $xmlrpcReq and Length are defined earlier. $host =…
Rich Bradshaw
  • 71,795
  • 44
  • 182
  • 241
3
votes
0 answers

python 3 file.close() Errorno 22 - accessing compact flash card

I am using python to directly access the bytes written on a compact flash card. With windows (the OS I am currently using) a drive can be accessed directly by adding a '\\\\.\\' (\\.\ when printed) before the drive name. The result is a string…
Nuclear_Man_D
  • 142
  • 11
3
votes
0 answers

PHP "failed to open stream - too many open files" error

I'm getting the PHP error failed to open stream: Too many open files. I suspect the problem is that I'm not closing something properly, but to find out what, I need to get a list of currently open files when this error occurs. How do I find this…
rowan.bradley
  • 147
  • 3
  • 9
3
votes
1 answer

Overwriting text file in C

I would like to start off with this is my first post and I am not doing this as a homework assignment, but rather to just introduce myself to writing in C. I'm trying to constantly overwrite the file with my for loop, however halfway through the…
J.Doge
  • 31
  • 2
3
votes
0 answers

Is it necessary to fclose pipes and proc_close processes

I am using a script to open (proc_open) from 5 to 50 processes one after another. Each of them does cURL and posts results to DB. I do not want to wait for their execution results, I just want them to run when the main script is axecuting and after…
Nikolay Antonov
  • 170
  • 1
  • 9
3
votes
2 answers

Free memory from file handler in PHP

Recently I started to face problems about memory management in PHP. This is something new to me because I never needed to run PHP scripts for long time on background threads. So, now I'm studying the subject and came to the simple script that…
Diego Andrade
  • 613
  • 7
  • 15
3
votes
3 answers

PHP console script / pass default arguments / refactoring fopen() fread() fwrite() fclose()

I wrote this tiny script to swap out colors on the Numix theme for Ubuntu Gnome:
RichardForrester
  • 1,048
  • 11
  • 19
3
votes
5 answers

Why would a file fail to open/close

I am trying to include statements that instruct the user a little bit more about why a file failed to open or close. What are some possible situations where a file would fail to open in write mode and what about failing to close? FILE *fp; if(!(fp…
Samuel
  • 395
  • 2
  • 5
  • 20
3
votes
3 answers

fclose()/pclose() may block on some file pointers

Calling fclose() here after dup()ing its file descriptor blocks until the child process has ended (presumably because the stream has ended). FILE *f = popen("./output", "r"); int d = dup(fileno(f)); fclose(f); However by manually performing the…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
3
votes
3 answers

How to detect, whether a FILE object is closed?

See the following code block, how I can make sure a FILE object is not closed before I call fclose on it? BTW, is it safe to call fclose twice? FILE* f = fopen('test.txt') //some code here, f may be closed by someone, but they may not set…
Patrick
  • 1,283
  • 2
  • 13
  • 20
3
votes
2 answers

What (might) happen if I use fclose() when fopen() failed

Here is my relatively simple scenario, and I'm wondering if I can save myself a conditional and tidy the code up a bit. Its production code that someone else wrote and I'm just tidying up. It had no fclose at all, so all I have added is the…
Steve
  • 1,439
  • 2
  • 14
  • 27
3
votes
8 answers

fclose() causing segmentation fault

I have a tab-delimited text file that I am parsing. Its first column contains strings of the format chrX, where X denotes a set of strings, e.g., "1", "2", ..., "X", "Y". These are each stored in a char* called chromosome, as the file is parsed.…
Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
2
votes
1 answer

PHP fopen($url,w)

$url="http://www.source.com/top"; $destination=fopen("/var/www/vhosts/domain.com/httpdocs/temp/" . date('m-d-Y'),"w"); echo "dest=$destination
"; echo "url=$url
"; $source=fopen($url,"r"); $maxsize=5000000000; $length=0; while…
user914425
  • 16,303
  • 4
  • 30
  • 41
1 2
3
18 19