473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

fwrite when out of storage space

I have a problem that has long plagued me:
What is the best way to check if I'm out of space?
I have a file editor application (could apply to anything though).
If the server (Apache on SunOS) is out of diskspace
$fp = fopen($file,'w');
fwrite($fp,$string,strlen($string));
fclose($fp);
creates a nice 0-byte file.. no error or anything.

Do I need to write to a test file and check it's filesize first??
There's gotta be a better way.

This is a server where the log files get out of control and that's out
of my jurisdiction.
Jul 16 '05 #1
4 2489
Hi,

BKDotCom wrote:
I have a problem that has long plagued me:
What is the best way to check if I'm out of space?
I have a file editor application (could apply to anything though).
If the server (Apache on SunOS) is out of diskspace
$fp = fopen($file,'w');
fwrite($fp,$string,strlen($string));
fclose($fp);
creates a nice 0-byte file.. no error or anything.

Do I need to write to a test file and check it's filesize first??
There's gotta be a better way.

This is a server where the log files get out of control and that's out
of my jurisdiction.


http://uk2.php.net/manual/en/functio...free-space.php

Luke

Jul 16 '05 #2
BKDotCom wrote:

I have a problem that has long plagued me:
What is the best way to check if I'm out of space?
I have a file editor application (could apply to anything though).
If the server (Apache on SunOS) is out of diskspace
$fp = fopen($file,'w');
fwrite($fp,$string,strlen($string));
fclose($fp);
creates a nice 0-byte file.. no error or anything.

Have you tried checking the return from fclose() in this situation? In
C, there usually will be an error return because the file buffers can't
be written. Similarly an explicit fflush() normally indicates error when
the data cannot be physically written to the device.


Brian Rodenborn
Jul 16 '05 #3
Thanks!
However I have brought shame to my family...
not sure how I missed that... old problem though.. pre ver 4.1

Luke Ross <lu******@sys3175.co.uk> wrote in message news:<vk************@corp.supernews.com>...
Hi,

BKDotCom wrote:
I have a problem that has long plagued me:
What is the best way to check if I'm out of space?
I have a file editor application (could apply to anything though).
If the server (Apache on SunOS) is out of diskspace
$fp = fopen($file,'w');
fwrite($fp,$string,strlen($string));
fclose($fp);
creates a nice 0-byte file.. no error or anything.

Do I need to write to a test file and check it's filesize first??
There's gotta be a better way.

This is a server where the log files get out of control and that's out
of my jurisdiction.


http://uk2.php.net/manual/en/functio...free-space.php

Luke

Jul 16 '05 #4
I'm pretty sure the return value was always non-false.
Not like a false value does any good after it's wiped the file.

Default User <fi********@company.com> wrote in message

Have you tried checking the return from fclose() in this situation? In
C, there usually will be an error return because the file buffers can't
be written. Similarly an explicit fflush() normally indicates error when
the data cannot be physically written to the device.

Brian Rodenborn

Jul 16 '05 #5

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

Similar topics

5
by: Matthias Kaeppler | last post by:
Hi, say I have a class X, such that: class X { A a; B b; C c; ...
23
by: FrancisC | last post by:
how to use fwrite( ) instead of fprintf( ) in this case? I want to generate binary file. FILE *fnew; int i, intName; double array; fprintf(fnew, "%d\n", intName);...
15
by: Suraj Kurapati | last post by:
Hello, I'm having a rather strange bug with this code: for certain values of 'buf', a segmentation fault occurs when 'free(buf)' is followed by an 'fwrite()'. In the program output, there is no...
6
by: sumit1680 | last post by:
Hi everyone, I am using the below listed code #include<stdio.h> #include<stdlib.h> #include<string.h> int main()
2
by: Richard Hsu | last post by:
// code #include "stdio.h" int status(FILE * f) { printf("ftell:%d, feof:%s\n", ftell(f), feof(f) != 0 ? "true" : "false"); } int case1() { FILE * f = fopen("c:\\blah", "wb+"); int i = 5;
13
by: Kantha | last post by:
Hi all, I have declared an Union as follows typedef union { struct interrupt_bits { unsigned char c_int_hs_fs_status : 1, c_setup_intflag : 1,
14
by: Richard Harter | last post by:
Apologies for the length - this post is best viewed with fixed font and a line width >= 72. Below is the source code for a C header file that provides a suite of storage management macros. I am...
12
by: arnuld | last post by:
WANTED: Even if I do Ctrl-C in the middle of fgets(), fwrite() should write the previously entered data to a file (except if I hit the file-size limit) PROBLEM: If I do a Ctrl-C in the...
6
by: Scott | last post by:
Hi, Which is faster writing to a file using fwrite or is using a database to store data? I want to create a log file and it does not matter if it is in a text file or on a database. I just...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.