This is an automated email from the ASF dual-hosted git repository.

wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 950cf26f Refactor NULL with nullptr in butil/files (#3440)
950cf26f is described below

commit 950cf26f9b262b443c466cfe39cc86ffb8eb68bb
Author: Bright Chen <[email protected]>
AuthorDate: Sat Aug 15 13:55:57 2026 +0800

    Refactor NULL with nullptr in butil/files (#3440)
---
 src/butil/files/dir_reader_linux.h          |  2 +-
 src/butil/files/dir_reader_unix.h           | 14 +++++++-------
 src/butil/files/file_path.cc                | 10 +++++-----
 src/butil/files/file_path.h                 |  2 +-
 src/butil/files/file_watcher.cpp            |  4 ++--
 src/butil/files/file_watcher.h              |  4 ++--
 src/butil/files/memory_mapped_file.cc       |  2 +-
 src/butil/files/memory_mapped_file_posix.cc |  8 ++++----
 src/butil/files/scoped_file.h               | 20 ++++++++++----------
 src/butil/files/temp_file.cpp               |  2 +-
 10 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/src/butil/files/dir_reader_linux.h 
b/src/butil/files/dir_reader_linux.h
index c7015464..72d486a6 100644
--- a/src/butil/files/dir_reader_linux.h
+++ b/src/butil/files/dir_reader_linux.h
@@ -70,7 +70,7 @@ class DirReaderLinux {
 
   const char* name() const {
     if (!size_)
-      return NULL;
+      return nullptr;
 
     const linux_dirent* dirent =
         reinterpret_cast<const linux_dirent*>(&buf_[offset_]);
diff --git a/src/butil/files/dir_reader_unix.h 
b/src/butil/files/dir_reader_unix.h
index 3c25f792..51c9eaa8 100644
--- a/src/butil/files/dir_reader_unix.h
+++ b/src/butil/files/dir_reader_unix.h
@@ -37,14 +37,14 @@ class DirReaderUnix {
  public:
   explicit DirReaderUnix(const char* directory_path)
       : fd_(open(directory_path, O_RDONLY | O_DIRECTORY)),
-        dir_(NULL),current_(NULL) {
+        dir_(nullptr),current_(nullptr) {
       dir_ = fdopendir(fd_);
   }
 
   ~DirReaderUnix() {
-    if (NULL != dir_) {
+    if (nullptr != dir_) {
       if (IGNORE_EINTR(closedir(dir_)) == 0) { // this implicitly closes fd_
-        dir_ = NULL;
+        dir_ = nullptr;
       } else {
         RAW_LOG(ERROR, "Failed to close directory.");
       }
@@ -52,21 +52,21 @@ class DirReaderUnix {
   }
 
   bool IsValid() const {
-    return dir_ != NULL;
+    return dir_ != nullptr;
   }
 
   // Move to the next entry returning false if the iteration is complete.
   bool Next() {
     int err = readdir_r(dir_,&entry_, &current_);
-    if(0 != err || NULL == current_){
+    if(0 != err || nullptr == current_){
         return false;
     }
     return true;
   }
 
   const char* name() const {
-    if (NULL == current_)
-      return NULL;
+    if (nullptr == current_)
+      return nullptr;
     return current_->d_name;
   }
 
diff --git a/src/butil/files/file_path.cc b/src/butil/files/file_path.cc
index e6188546..c5176af7 100644
--- a/src/butil/files/file_path.cc
+++ b/src/butil/files/file_path.cc
@@ -253,7 +253,7 @@ void FilePath::GetComponents(std::vector<StringType>* 
components) const {
 }
 
 bool FilePath::IsParent(const FilePath& child) const {
-  return AppendRelativePath(child, NULL);
+  return AppendRelativePath(child, nullptr);
 }
 
 bool FilePath::AppendRelativePath(const FilePath& child,
@@ -292,7 +292,7 @@ bool FilePath::AppendRelativePath(const FilePath& child,
     ++child_comp;
   }
 
-  if (path != NULL) {
+  if (path != nullptr) {
     for (; child_comp != child_components.end(); ++child_comp) {
       *path = path->Append(*child_comp);
     }
@@ -1159,7 +1159,7 @@ int FilePath::HFSFastUnicodeCompare(const StringType& 
string1,
 StringType FilePath::GetHFSDecomposedForm(const StringType& string) {
   ScopedCFTypeRef<CFStringRef> cfstring(
       CFStringCreateWithBytesNoCopy(
-          NULL,
+          nullptr,
           reinterpret_cast<const UInt8*>(string.c_str()),
           string.length(),
           kCFStringEncodingUTF8,
@@ -1206,7 +1206,7 @@ int FilePath::CompareIgnoreCase(const StringType& string1,
     NOTREACHED();
     ScopedCFTypeRef<CFStringRef> cfstring1(
         CFStringCreateWithBytesNoCopy(
-            NULL,
+            nullptr,
             reinterpret_cast<const UInt8*>(string1.c_str()),
             string1.length(),
             kCFStringEncodingUTF8,
@@ -1214,7 +1214,7 @@ int FilePath::CompareIgnoreCase(const StringType& string1,
             kCFAllocatorNull));
     ScopedCFTypeRef<CFStringRef> cfstring2(
         CFStringCreateWithBytesNoCopy(
-            NULL,
+            nullptr,
             reinterpret_cast<const UInt8*>(string2.c_str()),
             string2.length(),
             kCFStringEncodingUTF8,
diff --git a/src/butil/files/file_path.h b/src/butil/files/file_path.h
index c91f1f5a..a8e9a55a 100644
--- a/src/butil/files/file_path.h
+++ b/src/butil/files/file_path.h
@@ -202,7 +202,7 @@ class BUTIL_EXPORT FilePath {
   // parent.
   bool IsParent(const FilePath& child) const;
 
-  // If IsParent(child) holds, appends to path (if non-NULL) the
+  // If IsParent(child) holds, appends to path (if non-nullptr) the
   // relative path to child and returns true.  For example, if parent
   // holds "/Users/johndoe/Library/Application Support", child holds
   // "/Users/johndoe/Library/Application Support/Google/Chrome/Default", and
diff --git a/src/butil/files/file_watcher.cpp b/src/butil/files/file_watcher.cpp
index 5c697652..ad841569 100644
--- a/src/butil/files/file_watcher.cpp
+++ b/src/butil/files/file_watcher.cpp
@@ -33,12 +33,12 @@ int FileWatcher::init(const char* file_path) {
     if (init_from_not_exist(file_path) != 0) {
         return -1;
     }
-    check_and_consume(NULL);
+    check_and_consume(nullptr);
     return 0;
 }
 
 int FileWatcher::init_from_not_exist(const char* file_path) {
-    if (NULL == file_path) {
+    if (nullptr == file_path) {
         return -1;
     }
     if (!_file_path.empty()) {
diff --git a/src/butil/files/file_watcher.h b/src/butil/files/file_watcher.h
index 548e70b0..1b65282a 100644
--- a/src/butil/files/file_watcher.h
+++ b/src/butil/files/file_watcher.h
@@ -55,7 +55,7 @@ public:
     int init_from_not_exist(const char* file_path);
 
     // Check and consume change of the watched file. Write `last_timestamp'
-    // if it's not NULL.
+    // if it's not nullptr.
     // Returns:
     //   CREATE    the file is created since last call to this method.
     //   UPDATED   the file is modified since last call.
@@ -64,7 +64,7 @@ public:
     // Note: If the file is updated too frequently, this method may return 
     // UNCHANGED due to precision of stat(2) and the file system. If the file
     // is created and deleted too frequently, the event may not be detected.
-    Change check_and_consume(Timestamp* last_timestamp = NULL);
+    Change check_and_consume(Timestamp* last_timestamp = nullptr);
 
     // Set internal timestamp. User can use this method to make
     // check_and_consume() replay the change.
diff --git a/src/butil/files/memory_mapped_file.cc 
b/src/butil/files/memory_mapped_file.cc
index 95dae4f2..8f0e8f8d 100644
--- a/src/butil/files/memory_mapped_file.cc
+++ b/src/butil/files/memory_mapped_file.cc
@@ -47,7 +47,7 @@ bool MemoryMappedFile::Initialize(File file) {
 }
 
 bool MemoryMappedFile::IsValid() const {
-  return data_ != NULL;
+  return data_ != nullptr;
 }
 
 }  // namespace butil
diff --git a/src/butil/files/memory_mapped_file_posix.cc 
b/src/butil/files/memory_mapped_file_posix.cc
index 2901ac3d..0ce863c3 100644
--- a/src/butil/files/memory_mapped_file_posix.cc
+++ b/src/butil/files/memory_mapped_file_posix.cc
@@ -13,7 +13,7 @@
 
 namespace butil {
 
-MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0) {
+MemoryMappedFile::MemoryMappedFile() : data_(nullptr), length_(0) {
 }
 
 bool MemoryMappedFile::MapFileToMemory() {
@@ -27,7 +27,7 @@ bool MemoryMappedFile::MapFileToMemory() {
   length_ = file_stat.st_size;
 
   data_ = static_cast<uint8_t*>(
-      mmap(NULL, length_, PROT_READ, MAP_SHARED, file_.GetPlatformFile(), 0));
+      mmap(nullptr, length_, PROT_READ, MAP_SHARED, file_.GetPlatformFile(), 
0));
   if (data_ == MAP_FAILED)
     DPLOG(ERROR) << "mmap " << file_.GetPlatformFile();
 
@@ -37,11 +37,11 @@ bool MemoryMappedFile::MapFileToMemory() {
 void MemoryMappedFile::CloseHandles() {
   ThreadRestrictions::AssertIOAllowed();
 
-  if (data_ != NULL)
+  if (data_ != nullptr)
     munmap(data_, length_);
   file_.Close();
 
-  data_ = NULL;
+  data_ = nullptr;
   length_ = 0;
 }
 
diff --git a/src/butil/files/scoped_file.h b/src/butil/files/scoped_file.h
index 4d4d6ea1..1e6b93a7 100644
--- a/src/butil/files/scoped_file.h
+++ b/src/butil/files/scoped_file.h
@@ -49,10 +49,10 @@ typedef ScopedGeneric<int, internal::ScopedFDCloseTraits> 
ScopedFD;
 class ScopedFILE {
     MOVE_ONLY_TYPE_FOR_CPP_03(ScopedFILE, RValue);
 public:
-    ScopedFILE() : _fp(NULL) {}
+    ScopedFILE() : _fp(nullptr) {}
 
     // Open file at |path| with |mode|.
-    // If fopen failed, operator FILE* returns NULL and errno is set.
+    // If fopen failed, operator FILE* returns nullptr and errno is set.
     ScopedFILE(const char *path, const char *mode) {
         _fp = fopen(path, mode);
     }
@@ -63,13 +63,13 @@ public:
 
     ScopedFILE(RValue rvalue) {
         _fp = rvalue.object->_fp;
-        rvalue.object->_fp = NULL;
+        rvalue.object->_fp = nullptr;
     }
 
     ~ScopedFILE() {
-        if (_fp != NULL) {
+        if (_fp != nullptr) {
             fclose(_fp);
-            _fp = NULL;
+            _fp = nullptr;
         }
     }
 
@@ -78,20 +78,20 @@ public:
         reset(fopen(path, mode));
     }
 
-    void reset() { reset(NULL); }
+    void reset() { reset(nullptr); }
 
     void reset(FILE *fp) {
-        if (_fp != NULL) {
+        if (_fp != nullptr) {
             fclose(_fp);
-            _fp = NULL;
+            _fp = nullptr;
         }
         _fp = fp;
     }
 
-    // Set internal FILE* to NULL and return previous value.
+    // Set internal FILE* to nullptr and return previous value.
     FILE* release() {
         FILE* const prev_fp = _fp;
-        _fp = NULL;
+        _fp = nullptr;
         return prev_fp;
     }
     
diff --git a/src/butil/files/temp_file.cpp b/src/butil/files/temp_file.cpp
index d48499a0..234ec7f3 100644
--- a/src/butil/files/temp_file.cpp
+++ b/src/butil/files/temp_file.cpp
@@ -45,7 +45,7 @@ TempFile::TempFile() : _ever_opened(0) {
 }
 
 TempFile::TempFile(const char* ext) {
-    if (NULL == ext || '\0' == *ext) {
+    if (nullptr == ext || '\0' == *ext) {
         new (this) TempFile();
         return;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to