@@ -284,104 +284,12 @@ class PosixEnv : public Env {
284284#endif
285285 }
286286
287- void SleepForMicroseconds (int64_t micros) const override {
288- while (micros > 0 ) {
289- timespec sleep_time;
290- sleep_time.tv_sec = 0 ;
291- sleep_time.tv_nsec = 0 ;
292-
293- if (micros >= OneMillion) {
294- sleep_time.tv_sec = static_cast <time_t >(std::min<int64_t >(micros / OneMillion,
295- std::numeric_limits<time_t >::max ()));
296- micros -= static_cast <int64_t >(sleep_time.tv_sec ) * OneMillion;
297- }
298- if (micros < OneMillion) {
299- sleep_time.tv_nsec = static_cast <decltype (timespec::tv_nsec)>(1000 * micros);
300- micros = 0 ;
301- }
302- while (nanosleep (&sleep_time, &sleep_time) != 0 && errno == EINTR) {
303- // Ignore signals and wait for the full interval to elapse.
304- }
305- }
306- }
307287
308288 PIDType GetSelfPid () const override {
309289 return getpid ();
310290 }
311291
312- Status GetFileLength (const PathChar* file_path, size_t & length) const override {
313- ScopedFileDescriptor file_descriptor{open (file_path, O_RDONLY)};
314- return GetFileLength (file_descriptor.Get (), length);
315- }
316-
317- common::Status GetFileLength (int fd, /* out*/ size_t & file_size) const override {
318- using namespace common ;
319- if (fd < 0 ) {
320- return ORT_MAKE_STATUS (ONNXRUNTIME, INVALID_ARGUMENT, " Invalid fd was supplied: " , fd);
321- }
322-
323- struct stat buf;
324- int rc = fstat (fd, &buf);
325- if (rc < 0 ) {
326- return ReportSystemError (" fstat" , " " );
327- }
328-
329- if (buf.st_size < 0 ) {
330- return ORT_MAKE_STATUS (SYSTEM, FAIL, " Received negative size from stat call" );
331- }
332-
333- if (static_cast <unsigned long long >(buf.st_size ) > std::numeric_limits<size_t >::max ()) {
334- return ORT_MAKE_STATUS (SYSTEM, FAIL, " File is too large." );
335- }
336-
337- file_size = static_cast <size_t >(buf.st_size );
338- return Status::OK ();
339- }
340-
341- Status ReadFileIntoBuffer (const ORTCHAR_T* file_path, FileOffsetType offset, size_t length,
342- gsl::span<char > buffer) const override {
343- ORT_RETURN_IF_NOT (file_path, " file_path == nullptr" );
344- ORT_RETURN_IF_NOT (offset >= 0 , " offset < 0" );
345- ORT_RETURN_IF_NOT (length <= buffer.size (), " length > buffer.size()" );
346-
347- ScopedFileDescriptor file_descriptor{open (file_path, O_RDONLY)};
348- if (!file_descriptor.IsValid ()) {
349- return ReportSystemError (" open" , file_path);
350- }
351-
352- if (length == 0 )
353- return Status::OK ();
354-
355- if (offset > 0 ) {
356- const FileOffsetType seek_result = lseek (file_descriptor.Get (), offset, SEEK_SET);
357- if (seek_result == -1 ) {
358- return ReportSystemError (" lseek" , file_path);
359- }
360- }
361-
362- size_t total_bytes_read = 0 ;
363- while (total_bytes_read < length) {
364- constexpr size_t k_max_bytes_to_read = 1 << 30 ; // read at most 1GB each time
365- const size_t bytes_remaining = length - total_bytes_read;
366- const size_t bytes_to_read = std::min (bytes_remaining, k_max_bytes_to_read);
367-
368- const ssize_t bytes_read =
369- TempFailureRetry (read, file_descriptor.Get (), buffer.data () + total_bytes_read, bytes_to_read);
370-
371- if (bytes_read == -1 ) {
372- return ReportSystemError (" read" , file_path);
373- }
374-
375- if (bytes_read == 0 ) {
376- return ORT_MAKE_STATUS (ONNXRUNTIME, FAIL, " ReadFileIntoBuffer - unexpected end of file. " , " File: " , file_path,
377- " , offset: " , offset, " , length: " , length);
378- }
379-
380- total_bytes_read += bytes_read;
381- }
382-
383- return Status::OK ();
384- }
292+
385293
386294 static common::Status ReportSystemError (const char * operation_name, const std::string& path) {
387295 auto [err_no, err_msg] = GetErrnoInfo ();
@@ -390,16 +298,6 @@ class PosixEnv : public Env {
390298 return common::Status (common::SYSTEM, err_no, oss.str ());
391299 }
392300
393- common::Status GetCanonicalPath (
394- const PathString& path,
395- PathString& canonical_path) const override {
396- MallocdStringPtr canonical_path_cstr{realpath (path.c_str (), nullptr ), Freer<char >()};
397- if (!canonical_path_cstr) {
398- return ReportSystemError (" realpath" , path);
399- }
400- canonical_path.assign (canonical_path_cstr.get ());
401- return Status::OK ();
402- }
403301
404302 // \brief returns a value for the queried variable name (var_name)
405303 std::string GetEnvironmentVar (const std::string& var_name) const override {
0 commit comments