?
Solved

Replace fopen/fwrite

Posted on 2007-08-06
6
Medium Priority
?
1,087 Views
Last Modified: 2008-02-20
I would like to insert my own code each time a third party application writes to the disk. I have the source code and I thought the easiest way to do this is simply to replace fopen/fwrite with a function of my own that internally calls the real fopen/fwrite. How can I do this?

Thanks,
-Sandra
0
Comment
Question by:Sandra-24
6 Comments
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 19643040
Hello,
I think thaty you must write a resident in memory program that listen to int 13h for writing and reading disk.

-FA
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 19643136
Do you have the source code of the third party's fopen/fwrite? If you do, have you tried to call the ::fopen and ::fwrite functions?  If you just rename their fopen/fwrite functions so that their names are slightly different, then the next time you build the third party library it should pull in the standard c-runtime library version of fopen/fwrite.
0
 
LVL 9

Expert Comment

by:jasonclarke
ID: 19644368
An alternative might be to use something like the .NET FileSystemWatcher class - this raises events when specified I/O events take place (like changes to a particular directory or file).   There is a Win32 equivalent - ReadDirectoryChanges - but this is probably harder to use than the .NET class.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Accepted Solution

by:
grg99 earned 1000 total points
ID: 19648761

int My_fwrite( void * Buf, size_t Len, size_t Items, FILE * f ) {
// do whatever you want then:
   return  fwrite( Buf, Len, Items, f );
}



#define fopen  My_fopen
#define fclose  My_fclose
#define fread   My_fread
#define fwrite  My_fwrite



0
 
LVL 3

Author Comment

by:Sandra-24
ID: 19650738
Thanks grg99, that's exactly what I wanted.

Cheers,
-Sandra
0
 
LVL 22

Expert Comment

by:grg99
ID: 19653816
Note that this trick will work but only for sources you compile with this stuff included.

It won't change any fwrite's being done in linked in libraries.

Ands it won't trap any other kinds of writes, like with write()  and the other variations.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question