need a good idea for catch files deleted



  • 1. [re-post] why no output
    This compiles. Why no output? #include <stdio.h> #include <stdbool.h> #include <ctype.h> #include <stdlib.h> #define my_file "text42.txt" #define NUMBER 8192 bool get_script(FILE *, char *, int ); int main(void) { FILE *fp; char text[NUMBER]; bool len; if ((fp = fopen(my_file, "r")) == NULL ) { fprintf(stderr, "can't open file\n"); exit(EXIT_FAILURE); } while((len = get_script(fp, text, NUMBER)) > 0) { printf("%s\n", text); } fclose(fp); return 0; } // gcc s3.c -Wall -o out bool get_script(FILE* in, char* result, int size) { int ch; int i = 0; while (i < size - 1 && (ch = getc(in)) != EOF) { result[i++] = ch; int j = 0; for (; i + j < size - 1 && (isdigit(ch) || ch == ':'); ++j) { if (j + 1 == 10) { result[i + j] = '\0'; return true; } if ((ch = getc(in)) == EOF) { result[i + j] = '\0'; return false; } result[i + j] = ch; } i += j; } result[i] = '\0'; return false; } -- Frank I'm a perfectionist and if I start making changes, I'll never stop. ~~ Al Franken
  • 2. Macro to determine if a struct is a power of 2
    Hi, An API requires that buffers be powers of 2, so I borrowed a macro from Sean Anderson bit hacks page for the following macro: #define IS_NOT_POWER_OF_2(v) (((v) & ((v) - 1)) && (v)) I then test the condition: #if IS_NOT_POWER_OF_2(31) #error "Oops" #endif And this works perfectly. However when I try something closer to my intended use: #if IS_NOT_POWER_OF_2(sizeof(int)) #error "Oops" #endif gcc 3.4.4 reports: main.cpp:31:34: missing binary operator before token "(" cpp doesn't shed any light, and I have confirmed that my test fails to compile on other compilers, as well. What am I missing? Thanks
  • 3. arraysize seems to be wrong?
    Hello, I ran the following simple test: #define ARRAYSIZE(a) (sizeof(a)/sizeof(char)) #include <stdio.h> #include "chrutil.h" int main(void) { char *array = "12345"; char *p = array; printf("Arraysize: %d\n", ARRAYSIZE(array)); while (*p != '\0') { printf("Digit: %d\n", dig_to_int(*(p++))); } return 0; } int dig_to_int(char c) { if (IS_DIGIT(c)) { return c - '0'; } printf("Error: %c\n", c); } In this case, the macro ARRAYSIZE or even the simple function sizeof shows me that "array" has a size of 4? When I change the line with the array to char array[] = "12345"; it suddendly shows me that "array" has a size of 6? How can one explain that? Regards, Markus

need a good idea for catch files deleted

Postby elgiei » Mon, 14 May 2007 02:40:00 GMT

Good morning at all,
i have to implement a server,that every n-seconds (eg. 10sec) sends to
other clients,which files and directory  has been deleted or modified.

i build a n-tree, for each files on harddisk there's a node into n-
this solution is not good for large hard disk..
and i can't use inotify (it's forbidden),
and only c solutions are accepted
without third party software or external calls.
the Hard disk are both ext3 and NTFS.

anyone has a good idea for build an efficient server??

thanks a lot


Re: need a good idea for catch files deleted

Postby roberson » Mon, 14 May 2007 03:29:51 GMT

In article < XXXX@XXXXX.COM >,

No solution is possible within the constraints imposed. You are only
permitted to use C (you indicate), without third party software or
external calls, but you need external calls for two or more aspects
of the requirements:

1) C does not provide any mechanism to delay any particular amount
of time. The closest you can come is to "busy-loop", doing some
unnecessary work and checking the clock time to determine if you've
waited long enough. Busy-loops are inherently inefficient.
Most OS's provide means to delay for approximate times, but using
such an OS facility would be using an external call, not permitted
by your specifications.

2) C does not provide any mechanism to examine directories; C doesn't
know *anything* about directories. Most OS's provide means to examine
directories, but using such an OS facility would be using an external
call, not permitted by your specifications.

3) Your specifications require that information be periodically "sent"
to other clients. C does not provide any mechanims to communicate with
clients, other than whatever can be accomplished with regular files.
It is possible to come up with a reasonable information dissemination
method based upon writing out information (pre-pended with the size of
the information) to a known file, but if you want to do a traditional
client/server architecture, you would have to use OS-specific facilities
which would require external calls, not permitted by your

How are you constructing your n-trees? Are you doing prefix-sharing
so that if you have figure1.eps and figure17.eps, the "figure1" portion
only gets stored once?
   "No one has the right to destroy another person's belief by
   demanding empirical evidence."              -- Ann Landers

Re: need a good idea for catch files deleted

Postby llothar » Mon, 14 May 2007 03:41:59 GMT

Homework or real world problem ?

I'm afraid there isn't one. I used special code in my program but it
didn't work on linux reliable dnotify and on windows it always blocks
certain file operation so you can't use it either.

I came up with checking at certain times from a background thread.

Re: need a good idea for catch files deleted

Postby elgiei » Mon, 14 May 2007 07:24:53 GMT

irst of all thanks for your attention,
my server already works with
pthread, socket, signal for timer
and many feature offered by includes,
for external call i mean for example all the "exec" 's
family,whithin you can use any binary file on your /bin directory
(or .exe file).

my ntree has
a lot of node, the same number of files and directories.
a node is composed by n pointer one for each son

so if my hard disk is composed only by :

my ntree is :

--------- /--------\---------------------------
(remove "-" with space)

after 60secs i rebuild a new ntree and i do a diff (ntreeNEW,ntreeOLD)
and i check the differences..

but it's not a smart solution for large data.

is there a signal Handler for catch file removed ?
anyone has a better idea????

i repeat the problem
i have to implement a server,that every n-seconds (eg. 10sec) sends to
other clients,which files and directory has been deleted or
modified in the system (not by my server)
the problem is catching the deleted or modified files,whitout an
expensive ntree snapshot.

a solution:
i can read all Hard disk and i can understand which files was created
or modified in the last 60-sec,
but i don't know about the deleted files.

thanks a lot


On May 12, 8:29 pm, XXXX@XXXXX.COM (Walter Roberson)

Re: need a good idea for catch files deleted

Postby roberson » Mon, 14 May 2007 12:01:03 GMT

In article < XXXX@XXXXX.COM >,

None of those are part of standard C; those are all operating
system extensions.

This is sounding more and more like an assignment rather than a
real-life program.


So if there are duplicated prefixes, you store the prefix once per file?
That's less space efficient than it could be, but does make it easier
to insert or delete new nodes.

It seems to me that you don't need to build a new ntree and do a
comparison. Provided you use a consistant ordering (e.g., depth-first,
sorted order), you should be able to start at the beginning and trace
the existing ntree through for each file: if you are processing a
file that is not part of the current n-tree then it is a new file,
and if the next file does not correspond to the next node threaded
along the leaves, then any nodes that were skipped in the process
were removed (or renamed.) It shouldn't be difficult for you to
add threading between the leaves.

As I indicated earlier, standard C doesn't know anything about
directories -- and all it knows about files is that if you
pass a complete null-terminated string to fopen() then some
file somewhere will be opened (or the open will fail.) Standard C
doesn't know anything about what those filename strings -mean-.

Thus, of course there is no signal or any other method in standard C
of detecting that a file has been removed: the existance of such
a function would require knowing something about filesystems, which
standard C does not.

There might be a mechanism in your operating system to notice such
things, but any such facility would be OS-specific, and you would
need to inquire about it in a newsgroup that deals with your
(unnamed) operating system. (I wasn't able to deduce which OS you
are writing this for; you mentioned inotify() which appears to be
Linux-specific, and you mentioned ext3 filesystems, which appear
to be Linux-specific, but you also mentioned NTFS filesystems,
which are proprietary to Microsoft Windows.

What is the object of the assignment? To explore efficient use
of tree structures, or to explore how one would implement OS
facilities if those facilities were not already provided?
   Okay, buzzwords only. Two syllables, tops.  -- Laurie Anderson

Re: need a good idea for catch files deleted

Postby elgiei » Mon, 14 May 2007 19:37:36 GMT

gt;> elgiei < XXXX@XXXXX.COM > wrote:

ok i can use operative extensions infact in my code i used
#ifdef WIN32
and the else for linux..

i don't know if i really understand the prefixes
in each file i already stores path/file
i don't write in that picture for space's problem.


and really each node has a md5 (message digest) value
it's the sum of the md5 of his son
so if nothing is changed i don't need to compare both tree, so i
compare only the modified branch
(if someone don't understand this part can asks but it it's not useful
for the solution of the problem)
That's less space efficient (really less space efficient) but it's
faster (really faster)

yes it's a good solution,
but i build my new ntree becouse comparison is faster,
and after 60-sec it becomes the old ntree i have to build a new ntree
for comparison.

Yes my server must play on linux and win32
D'oh might be..
Anyone knows?
It's a great idea i'll search for win32 newsgroup and linux too
(suggested groups?)

is do a server for win and linux..
but the really problem is check in the better way,files deleted and
modified in filesystem ext3 Ntfs

Re: need a good idea for catch files deleted

Postby elgiei » Mon, 14 May 2007 21:17:13 GMT

my final solution is :

save my bigs ntree in memory (i'm studing)
 "Memory Mapped Files"
i hope it will be useful for the community.

Re: need a good idea for catch files deleted

Postby CBFalconer » Mon, 14 May 2007 22:36:25 GMT

lgiei wrote: *** and top-posted - fixed ***

I have preserved your entire post, less sigs, while fixing the

Please do not top-post. Your answer belongs after (or intermixed
with) the quoted material to which you reply, after snipping all
irrelevant material. See the following links:

<> (taming google)
<> (newusers)

Posted via a free Usenet account from

Similar Threads:

1.Nested conditional expressions ---- good idea/bad idea?

Below you will see an example of a nested conditional expression that
this colleague of mine loves.  He claims that it is more efficient that
a multi-level if-else-if structure.  Moreover, our complexity analyzer
tool supposedly does not pick it up.  Is it really more efficient?
Personally I find this coding style extremely cryptic, misleading and

I believe that I have removed all traces of proprietary-ness from this
coding example by multiple text substitutions.


#include <stdio.h>

#define QWER 0x1000
#define TYUI 0x2000
#define ASDF 0x4000
#define GHJK 0x8000
#define ZXCV 0x10000
#define BNML 0x20000

print_value(int code, int type)
printf(" ==>  %s, Type %02X \n",
(code == QWER      ? "QWER":
code == TYUI      ? "TYUI":
code == ASDF      ? "ASDF":
code == GHJK      ? "GHJK":
code == ZXCV      ? "ZXCV":
code == BNML      ? "BNML": "????"),

print_value(BNML, 256);
print_value(ZXCV, 512);
print_value(GHJK, 1024);
print_value(ASDF, 768);
print_value(TYUI, 128);
print_value(QWER, 64);
  print_value(BNML|QWER, 32);

2.EIP - catch "after delete record"

Hi all !

I have original EIP  browse. I need to  catch "after delete record". Where
is this embed point ?

Thanks !


3.any utilites out there for ideas to convert a *.h file to *.finc file

Hello ALL -

Looking for a utility that could help me parse a *.h file 
to a *.finc file for Assembly language.  Looking in particular for
parsing structions and unions ...


Thanks in advance.

4.delete-file & probe-file on directories

5.CLRFI and the ALU [was: delete-file & probe-file on directories]

6. (DELETE-FILE open-file-stream)

7. Help: file delete does not work on multiple files

8. good idea

Return to c


Who is online

Users browsing this forum: No registered users and 25 guest