anoniem Geplaatst: 27 januari 2002 Delen Geplaatst: 27 januari 2002 Hallo, Kan iemand mij aan een C-routine om de aanwezigheid van een file te testen, helpen? De routine moet in ANSI-C zijn omdat hij gebruikt wordt in een pakket dat alleen ANSI-C scripting ondersteunt. De test moet gedaan worden zonder dat de file, indien aanwezig, geopend wordt. Dus geen fopen; fclose statements, of pogingen de file te renamen. Het probleem is dat het C-script om de 5 minuten een tekstbestand aanmaakt, dat een andere PC constant tracht te openen, verwerken en als laatste weer verwijdert. Zonder voorziening treedt er in de tijd gezien een situatie op dat beide programma's gelijktijdig op dit bestand trachten toe te grijpen. Dit levert een conflict op. Dat laatste wil ik voorkomen door in het het C-script een test in te bouwen of het bestand al op de verwachte locatie aanwezig is. Pogingen de aanwezigheid te testen midddels renamen of met fopen, triggeren dezelfde conflict situatie, als zonder test. Bij voorbaat dank voor een ieders bijdrage Quote Link naar reactie
anoniem Geplaatst: 3 februari 2002 Auteur Delen Geplaatst: 3 februari 2002 Het kan aan mij liggen hoor, maar zo'n routine is toch niet echt moeilijk om te schrijven??? ik weet niet op welk platform het draait, maar als het onder Unix draait is er ook een heel simpel shell-script commandootje: test. Kan precies wat jij wilt en nog veel meer. Unix is in C geschreven dus als je er echt niet uitkomt rip je de code van test. moet je alleen wel de kernel-code doorspitten want het is een built-in commando en dat is misschien wel veel moeite voor zo'n simpele routine :wink: GreetzZzz Quote Link naar reactie
anoniem Geplaatst: 3 februari 2002 Auteur Delen Geplaatst: 3 februari 2002 ik bedoelde natuurlijk Linux. excuses aan alle oplettende Unix gurus hier op dit forum :wink: GreetzZzz Quote Link naar reactie
anoniem Geplaatst: 19 februari 2002 Auteur Delen Geplaatst: 19 februari 2002 struct stat stbuf; if (stat(<filenaam>, &stbuf) == -1) { /* file not found */ [evt. code] } else { [andere code] } [ Dit Bericht is bewerkt door: greffov op 2002-02-19 12:11 ] Quote Link naar reactie
anoniem Geplaatst: 19 februari 2002 Auteur Delen Geplaatst: 19 februari 2002 ehmmm, vergeet niet <sys/stat.h> te inkloeden. Quote Link naar reactie
anoniem Geplaatst: 19 februari 2002 Auteur Delen Geplaatst: 19 februari 2002 _access(<bestand>,00) zou ook moeten werken ... [code:1:b1570e5d81] Include: <io.h> Required only for function declarations <errno.h> Required only for definition of errno constants Syntax: int _access( char *pathname, int mode ); mode: 00 (existence) 04 (read permission) 02 (write permission) 06 (read & write permission) Returns: 0 if <pathname> has <mode>, or -1 if it does not have the given mode or if it does not exist. errno: EACCES, ENOENT See also: _stat, _chmod, _utime, _open [/code:1:b1570e5d81] // -- edit -- Voor 'stat()' moet het bestand al open zijn ... volgens de beschrijving hier : [code:1:b1570e5d81] The _fstat and _stat functions obtain information about an open file and store the information in the structure pointed to by <buffer>. The _fstat function specifies the file with a file handle and provides information about files and devices, but not directories. The _stat function specifies the file, which can include a path, and provides information about files but not drives or directories. [/code:1:b1570e5d81] _________________ - [url=http://jafo.mienadres.nl]JaFO's Bot-editor[/url] versie 2.0 - // --- Binnenkort(*) : JBE v2.5 - meer features - minder bugs - nog beter (*) "When it's done!" (natuurlijk) [ Dit Bericht is bewerkt door: JaFO op 2002-02-19 15:36 ] Quote Link naar reactie
anoniem Geplaatst: 19 februari 2002 Auteur Delen Geplaatst: 19 februari 2002 [code:1:d6be8595df]STAT(2) System calls STAT(2) NAME stat, fstat, lstat - get file status SYNOPSIS #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> int stat(const char *file_name, struct stat *buf); int fstat(int filedes, struct stat *buf); int lstat(const char *file_name, struct stat *buf); DESCRIPTION These functions return information about the specified file. You do not need any access rights to the file to get this information but you need search rights to all directories named in the path leading to the file. stat stats the file pointed to by file_name and fills in buf. lstat is identical to stat, except in the case of a sym bolic link, where the link itself is stat-ed, not the file that it refers to. fstat is identical to stat, only the open file pointed to by filedes (as returned by open(2)) is stated in place of file_name.[/code:1:d6be8595df] [i:d6be8595df]samengevat: fstat heeft volgens mij dus een filediscriptor nodig, stat een filename.[/i:d6be8595df] [ Dit Bericht is bewerkt door: greffov op 2002-02-19 18:23 ] Quote Link naar reactie
Aanbevolen berichten
Om een reactie te plaatsen, moet je eerst inloggen