#include #include #include #include "etc.h" #if defined(MSDOS) || defined(NT) #include #include #include #include #endif /* Ouverture avec sharing pour DOS */ FILE *fopen_share (const char *fname, const char *mode) { #if defined(MSDOS) || defined(NT) /* #Spécification: fopen / novell On indique a Novell que nous gérons nous même les sharing violation. Si un tel cas est détecté au moment du fopen(), on fait une pause et on essai à nouveau 5 fois. Ce traitement est fait en mode lecture seulement. */ #if defined(MSDOS) struct REGS in,out; in.h.ah = 0xdd; in.h.dl = 1; int86 (0x21,&in,&out); #endif if (strchr(mode,'r')!=NULL && strchr(mode,'+') == NULL){ int last_fmode = _fmode; if (strcmp(mode,"r")==0){ _fmode = O_RDONLY | O_TEXT | O_DENYNONE; }else if (strcmp(mode,"rb")==0){ _fmode = O_RDONLY | O_BINARY | O_DENYNONE; } int fd = -1; int compte = 5; while (compte > 0){ fd = open (fname,0,0); if (fd != -1){ break; }else if (errno != 128){ break; } fprintf (stderr,"Sharing violation --- sleeping 2 seconds\n"); sleep (2); compte--; } _fmode = last_fmode; return fd == -1 ? NULL : fdopen (fd,(char*)mode); }else{ return fopen (fname,mode); } #elif defined(NTTOTO) if (strchr(mode,'r')!=NULL && strchr(mode,'+') == NULL){ int lmode; if (strcmp(mode,"r")==0){ lmode = READ | O_TEXT | OF_SHARE_DENY_NONE; }else if (strcmp(mode,"rb")==0){ lmode = O_RDONLY | O_BINARY | OF_SHARE_DENY_NONE; } int fd = -1; int compte = 5; while (compte > 0){ fd = _lopen (fname,lmode); if (fd != HFILE_ERROR){ break; }else if (errno != 128){ break; } fprintf (stderr,"Sharing violation --- sleeping 2 seconds\n"); sleep (2); compte--; } return fd == HFILE_ERROR ? NULL : fdopen (fd,(char*)mode); }else{ return fopen (fname,mode); } #else return fopen (fname,mode); #endif }