file open

  • Thread starter emanshu, Munish Nayyar
  • Start date
E

emanshu, Munish Nayyar

HI all,

I an designing an application in C++. i want to open file requested by
end user but i want to reflect an error to user if file is already
opened by some other application..
will anybody tell me that how to know that the file is already open or
closed..

any help is highly appreciated...

thanks,
Munish Nayyar
emanshu "IM"
 
R

Richard Bos

emanshu said:
I an designing an application in C++. i want to open file requested by
end user but i want to reflect an error to user if file is already
opened by some other application..
will anybody tell me that how to know that the file is already open or
closed..

Basically, you cannot. All you can know is whether _you_ can open this
file. If you cannot, C has no way to tell the difference between a file
that is opened by someone else, a file that you have no rights to, or a
filename that is invalid. Trying to reliably tell the difference would
be hard anyway, on most systems.

Richard
 
E

emanshu, Munish Nayyar

Pieter said:
<snip>

You probably want comp.lang.c++. It's down the hall, to the right.
well, i know this is comp.lang.c group... but i am using still C-Style
fopen() and open().. i have access to g++ compiler only.if you have any
idea in c lang, how to acheive that , i will really appreciate any
help...

emanshu "IM"
 
P

Pieter Droogendijk

well, i know this is comp.lang.c group... but i am using still C-Style
fopen() and open().. i have access to g++ compiler only.if you have any
idea in c lang, how to acheive that , i will really appreciate any
help...

That doesn't change the fact that you're designing an application in C++.

At any rate, Richard Bos has been so kind to answer your question.
comp.unix.programmer might be able to help you further.
 
E

Emmanuel Delahaye

emanshu, Munish Nayyar a écrit :
well, i know this is comp.lang.c group... but i am using still C-Style
fopen() and open().. i have access to g++ compiler only.if you have any
idea in c lang, how to acheive that , i will really appreciate any
help...

If you use g++, you compile according to the C++ rules; all bets are
off. It's another language. Why don't you ask your admin to install gcc ?
 
J

Jordan Abel

HI all,

I an designing an application in C++. i want to open file requested by
end user but i want to reflect an error to user if file is already
opened by some other application..
will anybody tell me that how to know that the file is already open or
closed..

any help is highly appreciated...

You might want to ask in comp.lang.c++, but keep in mind that a file
being already open by another application is not necessarily an error.
 
J

Joe Estock

HI all,

I an designing an application in C++. i want to open file requested by
end user but i want to reflect an error to user if file is already
opened by some other application..

You might have a system specific function for doing this. For example,
on my system I have access to flock(). Check the documentation for your
system to be sure.

[snip]

Joe
 
S

SM Ryan

# HI all,
#
# I an designing an application in C++. i want to open file requested by
# end user but i want to reflect an error to user if file is already
# opened by some other application..
# will anybody tell me that how to know that the file is already open or
# closed..

There is no standard way in C or C++. There is no reliable way
on some systems. You're going to have to find a solution (or
discover there is no solution) on a system by system basis.

With proper design you can hide system dependencies behind a
system independent interface.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top