Ga naar inhoud

C-routine om aanwezigheid bestand te testen


anoniem

Aanbevolen berichten

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
Link naar reactie
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
Link naar reactie
  • 3 weken later...
_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 ]
Link naar reactie
[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 ]
Link naar reactie

Om een reactie te plaatsen, moet je eerst inloggen

Gast
Reageer op dit topic

×   Geplakt als verrijkte tekst.   Herstel opmaak

  Er zijn maximaal 75 emoji toegestaan.

×   Je link werd automatisch ingevoegd.   Tonen als normale link

×   Je vorige inhoud werd hersteld.   Leeg de tekstverwerker

×   Je kunt afbeeldingen niet direct plakken. Upload of voeg afbeeldingen vanaf een URL in

  • Populaire leden

    Er is nog niemand die deze week reputatie heeft ontvangen.

  • Leden

    Geen leden om te tonen

×
×
  • Nieuwe aanmaken...