projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
An intro to the upgrade mutex in the Synchronized docs
[folly.git]
/
folly
/
File.h
diff --git
a/folly/File.h
b/folly/File.h
index 506181580844857efde6957b1ac102236b18a1f2..26d158e11f9b1fb5dca80ce228f24211077ad05e 100644
(file)
--- a/
folly/File.h
+++ b/
folly/File.h
@@
-1,5
+1,5
@@
/*
/*
- * Copyright 201
3
Facebook, Inc.
+ * Copyright 201
6
Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-14,13
+14,17
@@
* limitations under the License.
*/
* limitations under the License.
*/
-#ifndef FOLLY_FILE_H_
-#define FOLLY_FILE_H_
+#pragma once
+#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
+
+#include <string>
+
+#include <folly/Portability.h>
+#include <folly/Range.h>
+#include <folly/portability/Unistd.h>
namespace folly {
namespace folly {
@@
-38,15
+42,15
@@
class File {
* Create a File object from an existing file descriptor.
* Takes ownership of the file descriptor if ownsFd is true.
*/
* Create a File object from an existing file descriptor.
* Takes ownership of the file descriptor if ownsFd is true.
*/
- /* implicit */ File(int fd,
- bool ownsFd = false);
+ explicit File(int fd, bool ownsFd = false);
/**
* Open and create a file object. Throws on error.
*/
/**
* Open and create a file object. Throws on error.
*/
- /* implicit */ File(const char* name,
- int flags = O_RDONLY,
- mode_t mode = 0644);
+ explicit File(const char* name, int flags = O_RDONLY, mode_t mode = 0666);
+ explicit File(
+ const std::string& name, int flags = O_RDONLY, mode_t mode = 0666);
+ explicit File(StringPiece name, int flags = O_RDONLY, mode_t mode = 0666);
~File();
~File();
@@
-64,7
+68,7
@@
class File {
* Returns 'true' iff the file was successfully opened.
*/
explicit operator bool() const {
* Returns 'true' iff the file was successfully opened.
*/
explicit operator bool() const {
- return fd_
>= 0
;
+ return fd_
!= -1
;
}
/**
}
/**
@@
-85,9
+89,10
@@
class File {
bool closeNoThrow();
/**
bool closeNoThrow();
/**
- * Releases the file descriptor; no longer owned by this File.
+ * Returns and releases the file descriptor; no longer owned by this File.
+ * Returns -1 if the File object didn't wrap a file.
*/
*/
-
void release()
;
+
int release() noexcept
;
/**
* Swap this File with another.
/**
* Swap this File with another.
@@
-95,7
+100,7
@@
class File {
void swap(File& other);
// movable
void swap(File& other);
// movable
- File(File&&);
+ File(File&&)
noexcept
;
File& operator=(File&&);
// FLOCK (INTERPROCESS) LOCKS
File& operator=(File&&);
// FLOCK (INTERPROCESS) LOCKS
@@
-130,5
+135,3
@@
void swap(File& a, File& b);
} // namespace folly
} // namespace folly
-
-#endif /* FOLLY_FILE_H_ */