@@ -526,6 +526,226 @@ S32 LLAPRFile::seek(apr_file_t* file_handle, apr_seek_where_t where, S32 offset)
526526 }
527527}
528528
529+ // static
530+ S32 LLAPRFile::readEx (const std::string& filename, void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool)
531+ {
532+ LL_PROFILE_ZONE_SCOPED;
533+ // *****************************************
534+ LLAPRFilePoolScope scope (pool);
535+ apr_file_t * file_handle = open (filename, scope.getVolatileAPRPool (), APR_READ|APR_BINARY);
536+ // *****************************************
537+ if (!file_handle)
538+ {
539+ return 0 ;
540+ }
541+
542+ llassert (offset >= 0 );
543+
544+ if (offset > 0 )
545+ offset = LLAPRFile::seek (file_handle, APR_SET, offset);
546+
547+ apr_size_t bytes_read;
548+ if (offset < 0 )
549+ {
550+ bytes_read = 0 ;
551+ }
552+ else
553+ {
554+ bytes_read = nbytes ;
555+ apr_status_t s = apr_file_read (file_handle, buf, &bytes_read);
556+ if (s != APR_SUCCESS)
557+ {
558+ LL_WARNS (" APR" ) << " Attempting to read filename: " << filename << LL_ENDL;
559+ ll_apr_warn_status (s);
560+ bytes_read = 0 ;
561+ }
562+ else
563+ {
564+ llassert_always (bytes_read <= 0x7fffffff );
565+ }
566+ }
567+
568+ // *****************************************
569+ close (file_handle) ;
570+ // *****************************************
571+ return (S32)bytes_read;
572+ }
573+
574+ // static
575+ S32 LLAPRFile::writeEx (const std::string& filename, const void *buf, S32 offset, S32 nbytes, LLVolatileAPRPool* pool)
576+ {
577+ LL_PROFILE_ZONE_SCOPED;
578+ apr_int32_t flags = APR_CREATE|APR_WRITE|APR_BINARY;
579+ if (offset < 0 )
580+ {
581+ flags |= APR_APPEND;
582+ offset = 0 ;
583+ }
584+
585+ // *****************************************
586+ LLAPRFilePoolScope scope (pool);
587+ apr_file_t * file_handle = open (filename, scope.getVolatileAPRPool (), flags);
588+ // *****************************************
589+ if (!file_handle)
590+ {
591+ return 0 ;
592+ }
593+
594+ if (offset > 0 )
595+ {
596+ offset = LLAPRFile::seek (file_handle, APR_SET, offset);
597+ }
598+
599+ apr_size_t bytes_written;
600+ if (offset < 0 )
601+ {
602+ bytes_written = 0 ;
603+ }
604+ else
605+ {
606+ bytes_written = nbytes ;
607+ apr_status_t s = apr_file_write (file_handle, buf, &bytes_written);
608+ if (s != APR_SUCCESS)
609+ {
610+ LL_WARNS (" APR" ) << " Attempting to write filename: " << filename << LL_ENDL;
611+ if (APR_STATUS_IS_ENOSPC (s))
612+ {
613+ LLApp::notifyOutOfDiskSpace ();
614+ }
615+ ll_apr_warn_status (s);
616+ bytes_written = 0 ;
617+ }
618+ else
619+ {
620+ llassert_always (bytes_written <= 0x7fffffff );
621+ }
622+ }
623+
624+ // *****************************************
625+ LLAPRFile::close (file_handle);
626+ // *****************************************
627+
628+ return (S32)bytes_written;
629+ }
630+
631+ // static
632+ bool LLAPRFile::remove (const std::string& filename, LLVolatileAPRPool* pool)
633+ {
634+ apr_status_t s;
635+
636+ LLAPRFilePoolScope scope (pool);
637+ s = apr_file_remove (filename.c_str (), scope.getVolatileAPRPool ());
638+
639+ if (s != APR_SUCCESS)
640+ {
641+ ll_apr_warn_status (s);
642+ LL_WARNS (" APR" ) << " Attempting to remove filename: " << filename << LL_ENDL;
643+ return false ;
644+ }
645+ return true ;
646+ }
647+
648+ // static
649+ bool LLAPRFile::rename (const std::string& filename, const std::string& newname, LLVolatileAPRPool* pool)
650+ {
651+ apr_status_t s;
652+
653+ LLAPRFilePoolScope scope (pool);
654+ s = apr_file_rename (filename.c_str (), newname.c_str (), scope.getVolatileAPRPool ());
655+
656+ if (s != APR_SUCCESS)
657+ {
658+ ll_apr_warn_status (s);
659+ LL_WARNS (" APR" ) << " Attempting to rename filename: " << filename << LL_ENDL;
660+ return false ;
661+ }
662+ return true ;
663+ }
664+
665+ // static
666+ bool LLAPRFile::isExist (const std::string& filename, LLVolatileAPRPool* pool, apr_int32_t flags)
667+ {
668+ apr_file_t * apr_file;
669+ apr_status_t s;
670+
671+ LLAPRFilePoolScope scope (pool);
672+ s = apr_file_open (&apr_file, filename.c_str (), flags, APR_OS_DEFAULT, scope.getVolatileAPRPool ());
673+
674+ if (s != APR_SUCCESS || !apr_file)
675+ {
676+ return false ;
677+ }
678+ else
679+ {
680+ apr_file_close (apr_file) ;
681+ return true ;
682+ }
683+ }
684+
685+ // static
686+ S32 LLAPRFile::size (const std::string& filename, LLVolatileAPRPool* pool)
687+ {
688+ apr_file_t * apr_file;
689+ apr_finfo_t info;
690+ apr_status_t s;
691+
692+ LLAPRFilePoolScope scope (pool);
693+ s = apr_file_open (&apr_file, filename.c_str (), APR_READ, APR_OS_DEFAULT, scope.getVolatileAPRPool ());
694+
695+ if (s != APR_SUCCESS || !apr_file)
696+ {
697+ return 0 ;
698+ }
699+ else
700+ {
701+ apr_status_t s = apr_file_info_get (&info, APR_FINFO_SIZE, apr_file);
702+
703+ apr_file_close (apr_file) ;
704+
705+ if (s == APR_SUCCESS)
706+ {
707+ return (S32)info.size ;
708+ }
709+ else
710+ {
711+ return 0 ;
712+ }
713+ }
714+ }
715+
716+ // static
717+ bool LLAPRFile::makeDir (const std::string& dirname, LLVolatileAPRPool* pool)
718+ {
719+ apr_status_t s;
720+
721+ LLAPRFilePoolScope scope (pool);
722+ s = apr_dir_make (dirname.c_str (), APR_FPROT_OS_DEFAULT, scope.getVolatileAPRPool ());
723+
724+ if (s != APR_SUCCESS)
725+ {
726+ ll_apr_warn_status (s);
727+ LL_WARNS (" APR" ) << " Attempting to make directory: " << dirname << LL_ENDL;
728+ return false ;
729+ }
730+ return true ;
731+ }
732+
733+ // static
734+ bool LLAPRFile::removeDir (const std::string& dirname, LLVolatileAPRPool* pool)
735+ {
736+ apr_status_t s;
737+
738+ LLAPRFilePoolScope scope (pool);
739+ s = apr_file_remove (dirname.c_str (), scope.getVolatileAPRPool ());
740+
741+ if (s != APR_SUCCESS)
742+ {
743+ ll_apr_warn_status (s);
744+ LL_WARNS (" APR" ) << " Attempting to remove directory: " << dirname << LL_ENDL;
745+ return false ;
746+ }
747+ return true ;
748+ }
529749//
530750// end of static components of LLAPRFile
531751// *******************************************************************************************************************************
0 commit comments