473,473 Members | 4,257 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Checking if a file descriptor is valid

25 New Member
Does anybody know how to check if the file descriptor is valid?
Sep 18 '07 #1
3 5861
RRick
463 Recognized Expert Contributor
By file descriptor do you mean a C language FILE handle or one of those unix style integers used for IO? (I'm not sure what windows uses in this case.) In C++, there is a good and is_open method for checking valid streams.

One technique is to just do what you really want to do with the IO channel (i.e read, write, etc.) and religiously check the error code/state.
Sep 18 '07 #2
creativeinspiration
25 New Member
I mean unix style file integer descriptors ( i am writing this in linux).
Sep 18 '07 #3
RRick
463 Recognized Expert Contributor
Take a look at ioctl found in stropts.h. This supports a lot of different types of interaction. The man pages says this only works with streams (but yet again, I'm not sure what isn't a stream in unix).

The I_LOOK request might do what you need. There's also a bunch of flush requests that work with input and output streams.
Sep 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Bryan | last post by:
i'm curious to know how others handle the closing of files. i seem to always end up with this pattern even though i rarely see others do it. f1 = file('file1') try: # process f1 finally:...
8
by: Joe | last post by:
Hi, I want to use the C library function mkstemp. It returns a unix file descriptor (int) to an open file. How do I convert the file descriptor to a valid ofstream object? Thanks, Joe
6
by: Siddharth Taneja | last post by:
Hi, I have a very simple prg over here, trying to read the lines of a file #include <iostream> #include <fstream> #include <iostream> #include <string> using namespace std;
4
by: lynology | last post by:
I need help trying to figure why this piece of code gives me a "Bad File descriptor error" everytime I try to run it and invoke fflush. This piece of code simple outputs a char string to the output...
0
by: Terry Stebbens | last post by:
If I have a file descriptor created with a function like 'open', would I be write in thinking the only way to check that that descriptor is valid would be to do something like: if (-1 ==...
2
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified...
4
by: CSN | last post by:
At startup this appears in the log: WARNING: dup(0) failed after 3195 successes: Bad file descriptor What does it mean? __________________________________________________
5
rajiv07
by: rajiv07 | last post by:
Hi i have script for upload file to server.when i execute this script it gives Bad file Descriptor error.could u anybody help on this. use strict; use CGI; use CGI::Carp qw(fatalsToBrowser);...
9
by: Bill David | last post by:
I know it's very strange to do that since we have the file name when we call: int open(const char *pathname, int oflag,...); And we can store the file name for later usage. But I just wonder if...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.