- 時間撮記:
- 2016-4-11 下午02:30:32 (9 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Runtime/r3/linux/sysfs.cpp
r60424 r60427 238 238 /* Check for EOF */ 239 239 uint64_t offCur = 0; 240 uint 64_t offEnd = 0;240 uint8_t bRead; 241 241 rc = RTFileSeek(hFile, 0, RTFILE_SEEK_CURRENT, &offCur); 242 242 if (RT_SUCCESS(rc)) 243 rc = RTFileSeek(hFile, 0, RTFILE_SEEK_END, &offEnd); 244 if ( RT_SUCCESS(rc) 245 && offEnd > offCur) 246 rc = VERR_BUFFER_OVERFLOW; 243 { 244 int rc2 = RTFileRead(hFile, &bRead, 1, NULL); 245 if (RT_SUCCESS(rc2)) 246 { 247 rc = VERR_BUFFER_OVERFLOW; 248 249 rc2 = RTFileSeek(hFile, offCur, RTFILE_SEEK_BEGIN, NULL); 250 if (RT_FAILURE(rc2)) 251 rc = rc2; 252 } 253 else if (rc2 != VERR_EOF) 254 rc = rc2; 255 } 247 256 } 248 257 return rc; … … 253 262 { 254 263 if (!cchBuf) 255 cchBuf = strlen(pszBuf) ;264 cchBuf = strlen(pszBuf) + 1; /* Include the terminator */ 256 265 return RTFileWrite(hFile, pszBuf, cchBuf, pcchWritten); 257 266 } … … 274 283 /* Check for EOF */ 275 284 uint64_t offCur = 0; 276 uint 64_t offEnd = 0;285 uint8_t bRead; 277 286 rc = RTFileSeek(hFile, 0, RTFILE_SEEK_CURRENT, &offCur); 278 287 if (RT_SUCCESS(rc)) 279 rc = RTFileSeek(hFile, 0, RTFILE_SEEK_END, &offEnd); 280 if ( RT_SUCCESS(rc) 281 && offEnd > offCur) 282 rc = VERR_BUFFER_OVERFLOW; 288 { 289 int rc2 = RTFileRead(hFile, &bRead, 1, NULL); 290 if (RT_SUCCESS(rc2)) 291 { 292 rc = VERR_BUFFER_OVERFLOW; 293 294 rc2 = RTFileSeek(hFile, offCur, RTFILE_SEEK_BEGIN, NULL); 295 if (RT_FAILURE(rc2)) 296 rc = rc2; 297 } 298 else if (rc2 != VERR_EOF) 299 rc = rc2; 300 } 283 301 } 284 302 } … … 502 520 size_t cchRead = 0; 503 521 rc = RTLinuxSysFsReadStr(hFile, pszBuf, cchBuf, &cchRead); 504 RTFileClose(hFile);505 522 if ( RT_SUCCESS(rc) 506 523 && cchRead > 0) … … 508 525 char *pchNewLine = (char *)memchr(pszBuf, '\n', cchRead); 509 526 if (pchNewLine) 527 { 510 528 *pchNewLine = '\0'; 511 } 529 cchRead--; 530 } 531 } 532 else if ( rc == VERR_BUFFER_OVERFLOW 533 && cchRead > 0) 534 { 535 /* 536 * Check if the last character would have been a newline we filter out 537 * anyway and revert the buffer overflow. 538 */ 539 char achBuf[2]; 540 size_t cchPeek = 0; 541 uint64_t offCur = 0; 542 543 int rc2 = RTFileSeek(hFile, 0, RTFILE_SEEK_CURRENT, &offCur); 544 if (RT_SUCCESS(rc2)) 545 { 546 rc2 = RTLinuxSysFsReadStr(hFile, &achBuf[0], sizeof(achBuf), &cchPeek); 547 if ( RT_SUCCESS(rc2) 548 && cchPeek > 0) 549 rc2 = RTFileSeek(hFile, offCur, RTFILE_SEEK_BEGIN, NULL); 550 if ( RT_SUCCESS(rc2) 551 && cchPeek > 0 552 && achBuf[0] == '\n') 553 rc = VINF_SUCCESS; 554 } 555 } 556 557 RTFileClose(hFile); 512 558 513 559 if (pcchRead)
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器