void main() { /* 0 = defecto: 1 = a: 2 = b: 3 = c: */ char *q,a[100]; int i; i = getdisk(); if (getcurdir (0,a) == -1) { /* Por defecto */ q = _strerror ("Error en getcur dir()"); PRS(q); getch(); exit(1); } printf ("Directorio actual en %c: = %s\n",i + 'a',a); /* Determina el directorio actual en a: */ if (getcurdir (1,a) == -1) { /* Unidad a: */ q = _strerror ("Error en getcur dir()"); PRS(q); getch(); exit(1); } printf ("Directorio actual en a: = %s\n",a); getch(); }
// Format a Windows system or Winsock error message given an error code. static const char * format_errmsg (unsigned int errcode, const char *prefix) { static const size_t errmsgsize = 1024; static char errmsg[errmsgsize]; sprintf (errmsg, "%s: ", prefix); size_t len = strlen (errmsg); char *next = &errmsg[len]; size_t max_fmt = errmsgsize - len; if (0 != FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, errcode, 0, // Use default language next, (DWORD)max_fmt, 0)) { strcat (errmsg, "\n"); return errmsg; } errno = errcode; char *msg = _strerror (prefix); sprintf (errmsg, "err %d: %s", errcode, msg); return errmsg; }
int DOSFAM::SkipRecord(PGLOBAL g, bool header) { PDBUSER dup = (PDBUSER)g->Activityp->Aptr; // Skip this record if (!fgets(To_Buf, Buflen, Stream)) { if (feof(Stream)) return RC_EF; #if defined(UNIX) || defined(UNIV_LINUX) sprintf(g->Message, MSG(READ_ERROR), To_File, strerror(0)); #else sprintf(g->Message, MSG(READ_ERROR), To_File, _strerror(NULL)); #endif return RC_FX; } // endif fgets // Update progress information dup->ProgCur = GetPos(); if (header) { // For Delete Fpos = ftell(Stream); if (!UseTemp) Tpos = Spos = Fpos; // No need to move header } // endif header #if defined(THREAD) return RC_NF; // To have progress info #else return RC_OK; // To loop locally #endif } // end of SkipRecord
void CAimProto::report_file_error(TCHAR *fname) { TCHAR errmsg[512]; TCHAR* error = mir_a2t(_strerror(NULL)); mir_sntprintf(errmsg, TranslateT("Failed to open file: %s : %s"), fname, error); mir_free(error); ShowPopup((char*)errmsg, ERROR_POPUP | TCHAR_POPUP); }
LogFile::LogFile(CString &s, CCriticalSection *cs) : lpCS(cs), sLogName(s) { fLog = 0; if (!OpenLog("w")) { MessageBox(NULL, _strerror("Warning! Can't open log file"), NULL, MB_OK); fLog = 0; } }
bool checkFileOK( std::ifstream &istr, const std::string &fname, const std::string &fmess ) { if ( !istr ) { std::string ebuff = ( boost::format( "Failed to open %s (%s)" ) % fmess % fname ).str(); char *emess = _strerror( ebuff.c_str() ); MinosParameters::getMinosParameters() ->mshowMessage( emess ); return false; } return true; }
void main() { int id; char *p; if ( (id = _open ("prueba",O_WRONLY) ) == -1) { p = _strerror ("Error _open ()"); PRS (p); getch(); exit(1); } _close(id); getch(); }
void clunk::IOException::add_custom_message() { char buf[1024]; memset(buf, 0, sizeof(buf)); #ifdef _MSC_VER strncpy(buf, _strerror(NULL), sizeof(buf)); #else strncpy(buf, strerror(errno), sizeof(buf)); // if (strerror_r(errno, buf, sizeof(buf)-1) != 0) perror("strerror"); #endif add_message(buf); }
void main(int argc, char *argv[], char *env[]) { int i; char *p; i = execlpe ("c:\\bc\\work1\\prog.exe",argv[0],"llave",argv[2],NULL,env); if (i == -1) { p = _strerror ("Error en execlpe"); printf ("%s\n%d\n",p,argc); getch(); exit(1); } getch(); }
void main() { int id; long numero; char *p; if ( (numero = filelength (id) ) == -1 ) { p = _strerror ("Error! archivo cerrado()"); printf ("%d\n",numero); PRS (p); getch(); exit (1); } getch(); }
void main() { char *p,*a,q[100]; strcpy (q,"link.exe"); p = searchpath (q); /* El valor de q no cambia */ if (p == NULL) { a = _strerror ("Error en searchpath ()"); PRS(a); getch(); exit (1); } PRS(p); SALTO; getch(); }
void main() { int id; char *p; if ( (id = _creat ("prueba",FA_ARCH) ) == -1) { p = _strerror ("Error _creat()"); PRS (p); getch(); exit(1); } if ( _close (id) == -1) { p = strerror (errno); PRS (p); getch(); exit(1); } getch(); }
// read plaintext shader source file char *read_source(const char *file) { uint size, read = 0; FILE *f; struct stat s; char *buffer; char filename[BASEDIR_LENGTH + 1024]; _snprintf(filename, sizeof(filename), "%s/%s", basedir, file); if(stat(filename, &s)) { error("failed to stat file %s\n", filename); return 0; } size = s.st_size; buffer = driver_malloc(size + 1); f = fopen(filename, "r"); if(!f) { error("couldn't open file %s for reading: %s", filename, _strerror(NULL)); driver_free(buffer); return 0; } while(read < size) { uint ret = fread(&buffer[read], 1, size - read, f); if(ret == 0 && feof(f)) break; read += ret; } buffer[read] = 0; return buffer; }
bool LogFile::OpenLog(CString &sName, CCriticalSection *cs) { if (fLog) CloseLog(); sLogName = sName; lpCS = cs; CSingleLock singleLock (lpCS, TRUE); #if 0 HANDLE hLog = CreateFile((LPCTSTR)sLogName, GENERIC_READ|GENERIC_WRITE, 0, // share mode NULL, // security attributes OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hLog == INVALID_HANDLE_VALUE) { AfxMessageBox("Can't open log file", MB_ICONERROR); return false; } int fdLog = _open_osfhandle((intptr_t)hLog, _O_APPEND | _O_TEXT); if (fdLog == -1) { AfxMessageBox("Can't open log file", MB_ICONERROR); CloseHandle(hLog); return false; } fLog = _fdopen(fdLog, "a"); if (fLog == NULL) { #else if ((fLog =fopen((LPCTSTR)sLogName, "a")) == NULL) { #endif AfxMessageBox(_strerror("Warning! Can't open log file"), MB_ICONERROR); return (false); } return true; } bool LogFile::OpenLog (char *mode) { CSingleLock singleLock (lpCS, TRUE); // return if the log is already open if (fLog) return (true); #if 0 HANDLE hLog = CreateFile((LPCTSTR)sLogName, GENERIC_READ|GENERIC_WRITE, 0, // share mode NULL, // security attributes OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hLog == INVALID_HANDLE_VALUE) { AfxMessageBox("Can't open log file", MB_ICONERROR); return false; } int fdLog = _open_osfhandle((intptr_t)hLog, _O_APPEND | _O_TEXT); if (fdLog == -1) { AfxMessageBox("Can't open log file", MB_ICONERROR); CloseHandle(hLog); return false; } fLog = _fdopen(fdLog, "a"); if (fLog == NULL) { #else if ((fLog =fopen((LPCTSTR)sLogName, "a")) == NULL) { #endif AfxMessageBox(_strerror("Warning! Can't open log file"), MB_ICONERROR); return (false); } return true; } LogFile::~LogFile() { } void LogFile::EndLog() { Log ("This is the end !\n"); CloseLog(); }
int DOSFAM::ReadBuffer(PGLOBAL g) { char *p; int rc; if (!Stream) return RC_EF; if (trace > 1) htrc("ReadBuffer: Tdbp=%p To_Line=%p Placed=%d\n", Tdbp, Tdbp->To_Line, Placed); if (!Placed) { /*******************************************************************/ /* Record file position in case of UPDATE or DELETE. */ /*******************************************************************/ if (RecordPos(g)) return RC_FX; CurBlk = (int)Rows++; if (trace > 1) htrc("ReadBuffer: CurBlk=%d\n", CurBlk); } else Placed = false; if (trace > 1) htrc(" About to read: stream=%p To_Buf=%p Buflen=%d\n", Stream, To_Buf, Buflen); if (fgets(To_Buf, Buflen, Stream)) { p = To_Buf + strlen(To_Buf) - 1; if (trace > 1) htrc(" Read: To_Buf=%p p=%c\n", To_Buf, To_Buf, p); #if defined(UNIX) if (true) { // Data files can be imported from Windows (having CRLF) #else if (Bin) { // Data file is read in binary so CRLF remains #endif if (*p == '\n' || *p == '\r') { // is this enough for Unix ??? *p = '\0'; // Eliminate ending CR or LF character if (p > To_Buf) { // is this enough for Unix ??? p--; if (*p == '\n' || *p == '\r') *p = '\0'; // Eliminate ending CR or LF character } // endif To_Buf } // endif p } else if (*p == '\n') *p = '\0'; // Eliminate ending new-line character if (trace > 1) htrc(" To_Buf='%s'\n", To_Buf); strcpy(Tdbp->To_Line, To_Buf); num_read++; rc = RC_OK; } else if (feof(Stream)) { rc = RC_EF; } else { #if defined(UNIX) sprintf(g->Message, MSG(READ_ERROR), To_File, strerror(0)); #else sprintf(g->Message, MSG(READ_ERROR), To_File, _strerror(NULL)); #endif if (trace) htrc("%s\n", g->Message); rc = RC_FX; } // endif's fgets if (trace > 1) htrc("ReadBuffer: rc=%d\n", rc); IsRead = true; return rc; } // end of ReadBuffer /***********************************************************************/ /* WriteBuffer: File write routine for DOS access method. */ /***********************************************************************/ int DOSFAM::WriteBuffer(PGLOBAL g) { char *crlf = "\n"; int curpos = 0; bool moved = true; // T_Stream is the temporary stream or the table file stream itself if (!T_Stream) if (UseTemp && Tdbp->Mode == MODE_UPDATE) { if (OpenTempFile(g)) return RC_FX; } else T_Stream = Stream; if (Tdbp->Mode == MODE_UPDATE) { /*******************************************************************/ /* Here we simply rewrite a record on itself. There are two cases */ /* were another method should be used, a/ when Update apply to */ /* the whole file, b/ when updating the last field of a variable */ /* length file. The method could be to rewrite a new file, then */ /* to erase the old one and rename the new updated file. */ /*******************************************************************/ curpos = ftell(Stream); if (trace) htrc("Last : %d cur: %d\n", Fpos, curpos); if (UseTemp) { /*****************************************************************/ /* We are using a temporary file. Before writing the updated */ /* record, we must eventually copy all the intermediate records */ /* that have not been updated. */ /*****************************************************************/ if (MoveIntermediateLines(g, &moved)) return RC_FX; Spos = curpos; // New start position } else // Update is directly written back into the file, // with this (fast) method, record size cannot change. if (fseek(Stream, Fpos, SEEK_SET)) { sprintf(g->Message, MSG(FSETPOS_ERROR), 0); return RC_FX; } // endif } // endif mode /*********************************************************************/ /* Prepare the write buffer. */ /*********************************************************************/ #if defined(WIN32) if (Bin) crlf = "\r\n"; #endif // WIN32 strcat(strcpy(To_Buf, Tdbp->To_Line), crlf); /*********************************************************************/ /* Now start the writing process. */ /*********************************************************************/ if ((fputs(To_Buf, T_Stream)) == EOF) { sprintf(g->Message, MSG(FPUTS_ERROR), strerror(errno)); return RC_FX; } // endif EOF if (Tdbp->Mode == MODE_UPDATE && moved) if (fseek(Stream, curpos, SEEK_SET)) { sprintf(g->Message, MSG(FSEEK_ERROR), strerror(errno)); return RC_FX; } // endif if (trace) htrc("write done\n"); return RC_OK; } // end of WriteBuffer
//--------------------------------------------------------------------------- String TEntryOptionsForm::doFileSave( ) { SaveDialog->InitialDir = ExtractFilePath( ct->cfileName.c_str() ); String expName; String fname = ExtractFileName( ct->cfileName.c_str() ); String ext = ExtractFileExt( ct->cfileName.c_str() ); fname = fname.SubString( 1, fname.Length() - ext.Length() ); //enum ExportType {EREG1TEST, EADIF, EG0GJV, EMINOS, EKML, EPRINTFILE }; String defext; String filter; switch ( expformat ) { case EG0GJV: defext = "GJV"; filter = "GJV ContestLog files (*.gjv)|*.GJV|All Files (*.*)|*.*" ; break; case EMINOS: defext = "Minos"; filter = "Minos ContestLog files (*.minos)|*.MINOS|All Files (*.*)|*.*" ; break; case EADIF: defext = "ADI"; filter = "ADIF files (*.adi)|*.ADI|All Files (*.*)|*.*" ; break; case EKML: defext = "KML"; filter = "KML(GoogleEarth) files (*.kml)|*.KML|All Files (*.*)|*.*" ; break; case EREG1TEST: { defext = "EDI"; ct->mycall.valRes = CS_NOT_VALIDATED; ct->mycall.validate( ); filter = "Region 1 EDI files (*.edi)|*.EDI|All Files (*.*)|*.*" ; } break; case EPRINTFILE: { defext = "TXT"; filter = "Text output (*.txt)|*.TXT|All Files (*.*)|*.*" ; } break; } SaveDialog->FileName = fname; SaveDialog->DefaultExt = defext; SaveDialog->Filter = filter; while ( SaveDialog->Execute() ) { TWaitCursor fred; expName = SaveDialog->FileName; // open the export file struct stat sbuf; if ( stat( expName.c_str(), &sbuf ) == 0 ) { if ( !( sbuf.st_mode & S_IWRITE ) ) { MinosParameters::getMinosParameters() ->mshowMessage( "File is Read Only" ); return ""; } } if ( MinosParameters::getMinosParameters() ->isContestOpen( expName.c_str() ) ) { // then try again... continue; } HANDLE expfd = CreateFile( expName.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, 0, // security CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 ); // template handle if ( expfd == INVALID_HANDLE_VALUE ) { char * emess = _strerror( "Failed to create export file" ); MinosParameters::getMinosParameters() ->mshowMessage( emess ); return ""; } int ret = ct->export_contest( expfd, expformat ); CloseHandle( expfd ); if ( ret == -1 ) { unlink( expName.c_str() ); // failure response, so delete file again expName = ""; } break; } return expName; }
int BLKFAM::ReadBuffer(PGLOBAL g) { int i, n, rc = RC_OK; /*********************************************************************/ /* Sequential reading when Placed is not true. */ /*********************************************************************/ if (Placed) { Placed = false; } else if (++CurNum < Rbuf) { CurLine = NxtLine; // Get the position of the next line in the buffer while (*NxtLine++ != '\n') ; // Set caller line buffer n = NxtLine - CurLine - Ending; memcpy(Tdbp->GetLine(), CurLine, n); Tdbp->GetLine()[n] = '\0'; goto fin; } else if (Rbuf < Nrec && CurBlk != -1) { return RC_EF; } else { /*******************************************************************/ /* New block. */ /*******************************************************************/ CurNum = 0; if (++CurBlk >= Block) return RC_EF; } // endif's if (OldBlk == CurBlk) goto ok; // Block is already there // fseek is required only in non sequential reading if (CurBlk != OldBlk + 1) if (fseek(Stream, BlkPos[CurBlk], SEEK_SET)) { sprintf(g->Message, MSG(FSETPOS_ERROR), BlkPos[CurBlk]); return RC_FX; } // endif fseek // Calculate the length of block to read BlkLen = BlkPos[CurBlk + 1] - BlkPos[CurBlk]; if (trace) htrc("File position is now %d\n", ftell(Stream)); // Read the entire next block n = fread(To_Buf, 1, (size_t)BlkLen, Stream); if (n == BlkLen) { // ReadBlks++; num_read++; Rbuf = (CurBlk == Block - 1) ? Last : Nrec; ok: rc = RC_OK; // Get the position of the current line for (i = 0, CurLine = To_Buf; i < CurNum; i++) while (*CurLine++ != '\n') ; // What about Unix ??? // Now get the position of the next line for (NxtLine = CurLine; *NxtLine++ != '\n';) ; // Set caller line buffer n = NxtLine - CurLine - Ending; memcpy(Tdbp->GetLine(), CurLine, n); Tdbp->GetLine()[n] = '\0'; } else if (feof(Stream)) { rc = RC_EF; } else { #if defined(UNIX) sprintf(g->Message, MSG(READ_ERROR), To_File, strerror(errno)); #else sprintf(g->Message, MSG(READ_ERROR), To_File, _strerror(NULL)); #endif if (trace) htrc("%s\n", g->Message); return RC_FX; } // endelse OldBlk = CurBlk; // Last block actually read IsRead = true; // Is read indeed fin: // Store the current record file position for Delete and Update Fpos = BlkPos[CurBlk] + CurLine - To_Buf; return rc; } // end of ReadBuffer