mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
add __nonzero__, respect lockf() return value
This commit is contained in:
parent
661af56d60
commit
9f9316ff81
@ -572,6 +572,23 @@ compare_to(const Filename &other) const {
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Filename::__nonzero__
|
||||
// Access: Published
|
||||
// Description: Returns true if the Filename is valid (not empty),
|
||||
// or false if it is an empty string.
|
||||
//
|
||||
// This implements the Python equivalent to operator
|
||||
// bool. Defining an actual operator bool method for
|
||||
// C++ use would work too, but it seems to cause too
|
||||
// many ambiguities for the C++ compiler, so we use this
|
||||
// Python-only approach instead.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool Filename::
|
||||
__nonzero__() const {
|
||||
return !_filename.empty();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Filename::output
|
||||
// Access: Published
|
||||
|
@ -1559,7 +1559,7 @@ get_file_size() const {
|
||||
bool Filename::
|
||||
resolve_filename(const DSearchPath &searchpath,
|
||||
const string &default_extension) {
|
||||
string found;
|
||||
Filename found;
|
||||
|
||||
if (is_local()) {
|
||||
found = searchpath.find_file(*this);
|
||||
@ -2586,7 +2586,11 @@ atomic_compare_and_exchange_contents(string &orig_contents,
|
||||
|
||||
orig_contents = string();
|
||||
|
||||
lockf(fd, F_LOCK, 0);
|
||||
if (lockf(fd, F_LOCK, 0) != 0) {
|
||||
perror(os_specific.c_str());
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t bytes_read = read(fd, buf, buf_size);
|
||||
while (bytes_read > 0) {
|
||||
@ -2699,7 +2703,11 @@ atomic_read_contents(string &contents) const {
|
||||
|
||||
contents = string();
|
||||
|
||||
lockf(fd, F_LOCK, 0);
|
||||
if (lockf(fd, F_LOCK, 0) != 0) {
|
||||
perror(os_specific.c_str());
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t bytes_read = read(fd, buf, buf_size);
|
||||
while (bytes_read > 0) {
|
||||
|
@ -204,6 +204,7 @@ PUBLISHED:
|
||||
INLINE bool operator != (const string &other) const;
|
||||
INLINE bool operator < (const string &other) const;
|
||||
INLINE int compare_to(const Filename &other) const;
|
||||
INLINE bool __nonzero__() const;
|
||||
|
||||
INLINE void output(ostream &out) const;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user