62#if JUCE_MAC || JUCE_LINUX || JUCE_BSD
84 #ifndef JUCE_PREFERRED_MAX_FILE_HANDLES
102#if JUCE_ALLOW_STATIC_NULL_VARIABLES
104JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE (
"-Wdeprecated-declarations")
109JUCE_END_IGNORE_WARNINGS_GCC_LIKE
124 size_t bufferSize = 4096;
154 struct ::sigaction
act;
162 return ::sigaction (
sig, &
act,
nullptr);
169 #if JUCE_LINUX || (JUCE_IOS && (! TARGET_OS_MACCATALYST) && (! __DARWIN_ONLY_64_BIT_INO_T))
171 #define JUCE_STAT stat64
174 #define JUCE_STAT stat
180 && JUCE_STAT (
fileName.toUTF8(), &info) == 0;
187 for (
int i = 5; --i >= 0;)
192 f = f.getParentDirectory();
195 return statfs (f.getFullPathName().toUTF8(), &result) == 0;
198 #if JUCE_MAC || JUCE_IOS
205 Time* modTime, Time* creationTime,
bool* isReadOnly)
207 if (isDir !=
nullptr || fileSize !=
nullptr || modTime !=
nullptr || creationTime !=
nullptr)
212 if (isDir !=
nullptr) *isDir =
statOk && ((info.st_mode &
S_IFDIR) != 0);
213 if (fileSize !=
nullptr) *fileSize =
statOk ? (
int64) info.st_size : 0;
214 if (modTime !=
nullptr) *modTime = Time (
statOk ? (
int64) info.st_mtime * 1000 : 0);
215 if (creationTime !=
nullptr) *creationTime = Time (
statOk ? getCreationTime (info) * 1000 : 0);
218 if (isReadOnly !=
nullptr)
219 *isReadOnly =
access (path.toUTF8(),
W_OK) != 0;
259 return juce_stat (fullPath, info) ? info.st_size : 0;
268static bool hasEffectiveRootFilePermissions()
270 #if JUCE_LINUX || JUCE_BSD
281 return (hasEffectiveRootFilePermissions()
296static bool setFileModeFlags (
const String& fullPath, mode_t flags,
bool shouldSet)
noexcept
303 info.st_mode &= 0777;
306 info.st_mode |= flags;
310 return chmod (fullPath.toUTF8(), (mode_t) info.st_mode) == 0;
326 modificationTime = 0;
334 #if JUCE_MAC || (JUCE_IOS && __DARWIN_ONLY_64_BIT_INO_T)
335 modificationTime = (
int64) info.st_mtimespec.tv_sec * 1000 + info.st_mtimespec.tv_nsec / 1000000;
336 accessTime = (
int64) info.st_atimespec.tv_sec * 1000 + info.st_atimespec.tv_nsec / 1000000;
337 creationTime = (
int64) info.st_birthtimespec.tv_sec * 1000 + info.st_birthtimespec.tv_nsec / 1000000;
339 modificationTime = (
int64) info.st_mtime * 1000;
342 creationTime = (
int64) info.st_birthtime * 1000;
344 creationTime = (
int64) info.st_ctime * 1000;
357 #if JUCE_MAC || (JUCE_IOS && __DARWIN_ONLY_64_BIT_INO_T)
403bool File::moveInternal (
const File& dest)
const
408 if (isNonEmptyDirectory())
422bool File::replaceInternal (
const File& dest)
const
424 return moveInternal (dest);
427Result File::createDirectoryInternal (
const String&
fileName)
const
433int64 juce_fileSetPosition (
void* handle,
int64 pos)
435 if (handle !=
nullptr && lseek (
getFD (handle), (off_t) pos,
SEEK_SET) == pos)
441void FileInputStream::openHandle()
453 if (fileHandle !=
nullptr)
457size_t FileInputStream::readInternal (
void* buffer,
size_t numBytes)
461 if (fileHandle !=
nullptr)
463 result = ::read (
getFD (fileHandle), buffer, numBytes);
472 return (
size_t) result;
476void FileOutputStream::openHandle()
486 if (currentPosition >= 0)
512void FileOutputStream::closeHandle()
514 if (fileHandle !=
nullptr)
517 fileHandle =
nullptr;
521ssize_t FileOutputStream::writeInternal (
const void* data,
size_t numBytes)
523 if (fileHandle ==
nullptr)
526 auto result = ::write (
getFD (fileHandle), data, numBytes);
531 return (ssize_t) result;
535void FileOutputStream::flushInternal()
537 if (fileHandle !=
nullptr && fsync (
getFD (fileHandle)) == -1)
544 if (fileHandle ==
nullptr)
554 if (
auto s = ::getenv (name.
toUTF8()))
562void MemoryMappedFile::openInternal (
const File& file, AccessMode mode,
bool exclusive)
579 if (fileHandle != -1)
584 (
off_t) range.getStart());
593 range = Range<int64>();
603 if (address !=
nullptr)
611File juce_getExecutableFile();
612File juce_getExecutableFile()
626 static String filename = DLAddrReader::getFilename();
657 attrreference_t mountPointRef;
658 char mountPointSpace[MAXPATHLEN];
672 (
int)
attrBuf.mountPointRef.attr_length);
695void juce_runSystemCommand (
const String&);
696void juce_runSystemCommand (
const String& command)
701String juce_getOutputFromCommand (
const String&);
702String juce_getOutputFromCommand (
const String& command)
708 juce_runSystemCommand (command +
" > " +
tempFile.getFullPathName());
710 auto result =
tempFile.loadFileAsString();
718class InterProcessLock::Pimpl
721 Pimpl (
const String&,
int) {}
723 int handle = 1, refCount = 1;
813 int handle = 0, refCount = 1;
829 if (pimpl ==
nullptr)
833 if (pimpl->handle == 0)
841 return pimpl !=
nullptr;
851 if (pimpl !=
nullptr && --(pimpl->refCount) == 0)
860 if (valid && stackSize != 0)
870 auto* get() {
return valid ? &attr :
nullptr; }
885 return { scheduler, param.sched_priority };
891 const auto isRealtime =
rt.hasValue();
893 const auto priority = [&]
900 return jmap (
rt->getPriority(), 0, 10, min, max);
905 #if JUCE_MAC || JUCE_IOS
909 const auto p = [
prio]
923 if (min != 0 && max != 0)
924 return jmap (p, 0, 4, min, max);
930 #if JUCE_MAC || JUCE_IOS || JUCE_BSD
937 const auto scheduler = 0;
940 return { scheduler, priority };
945 #if JUCE_LINUX || JUCE_BSD
954 constexpr int getScheduler()
const {
return scheduler; }
955 constexpr int getPriority()
const {
return priority; }
975 return (
void*) handle;
978void Thread::closeThreadHandle()
981 threadHandle =
nullptr;
986 #if JUCE_IOS || JUCE_MAC
991 #elif JUCE_LINUX || JUCE_BSD || JUCE_ANDROID
993 || (JUCE_LINUX && (__GLIBC__ * 1000 + __GLIBC_MINOR__) >= 2012) \
994 || (JUCE_ANDROID && __ANDROID_API__ >= 9))
1017#if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
1018 #define SUPPORT_AFFINITIES 1
1023 #if SUPPORT_AFFINITIES
1027 for (
int i = 0; i < 32; ++i)
1029 if ((affinityMask & (
uint32) (1 << i)) != 0)
1033 JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE (
"-Wsign-conversion")
1035 JUCE_END_IGNORE_WARNINGS_GCC_LIKE
1039 #if (! JUCE_ANDROID) && ((! (JUCE_LINUX || JUCE_BSD)) || ((__GLIBC__ * 1000 + __GLIBC_MINOR__) >= 2004))
1065 return handle !=
nullptr;
1070 if (handle !=
nullptr)
1079 return handle !=
nullptr ?
dlsym (handle, functionName.toUTF8()) :
nullptr;
1083#if JUCE_LINUX || JUCE_ANDROID
1089 for (
int i = lines.
size(); --i >= 0;)
1090 if (lines[i].upToFirstOccurrenceOf (
":",
false,
false).trim().equalsIgnoreCase (key))
1091 return lines[i].fromFirstOccurrenceOf (
":",
false,
false).trim();
1104 auto exe = arguments[0].unquoted();
1115 auto result =
fork();
1122 else if (result == 0)
1141 for (
auto&
arg : arguments)
1142 if (
arg.isNotEmpty())
1143 argv.
add (
const_cast<char*
> (
arg.toRawUTF8()));
1162 if (readHandle !=
nullptr)
1165 if (pipeHandle != 0)
1169 bool isRunning()
noexcept
1189 int read (
void* dest,
int numBytes)
noexcept
1191 jassert (dest !=
nullptr && numBytes > 0);
1197 if (readHandle ==
nullptr && childPID != 0)
1198 readHandle =
fdopen (pipeHandle,
"r");
1200 if (readHandle !=
nullptr)
1220 bool killProcess()
const noexcept
1222 return ::kill (childPID,
SIGKILL) == 0;
1225 uint32 getExitCode()
noexcept
1228 return (
uint32) exitCode;
1238 return (
uint32) exitCode;
1248 FILE* readHandle = {};
1260 if (args.
size() == 0)
1265 if (activeProcess->childPID == 0)
1266 activeProcess.reset();
1268 return activeProcess !=
nullptr;
Holds a resizable array of primitive or copy-by-value objects.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...
CharType * getAddress() const noexcept
Returns the address that this pointer is pointing to.
bool start(const String &command, int streamFlags=wantStdOut|wantStdErr)
Attempts to launch a child process command.
bool tryEnter() const noexcept
Attempts to lock this critical section without blocking.
~CriticalSection() noexcept
Destructor.
CriticalSection() noexcept
Creates a CriticalSection object.
void enter() const noexcept
Acquires the lock.
void exit() const noexcept
Releases the lock.
void * getFunction(const String &functionName) noexcept
Tries to find a named function in the currently-open DLL, and returns a pointer to it.
bool open(const String &name)
Opens a DLL.
void close()
Releases the currently-open DLL, or has no effect if none was open.
Result truncate()
Attempts to truncate the file to the current write position.
void flush() override
If the stream is using a buffer, this will ensure it gets written out to the destination.
Represents a local file or directory.
int getVolumeSerialNumber() const
Returns the serial number of the volume on which this file lives.
bool isSymbolicLink() const
Returns true if this file is a link or alias that can be followed using getLinkedTarget().
bool isDirectory() const
Checks whether the file is a directory that exists.
bool setAsCurrentWorkingDirectory() const
Sets the current working directory to be this file.
static StringRef getSeparatorString()
The system-specific file separator character, as a string.
int64 getVolumeTotalSize() const
Returns the total size of the drive that contains this file.
int64 getBytesFreeOnVolume() const
Returns the number of bytes free on the drive that this file lives on.
bool hasWriteAccess() const
Checks whether a file can be created or written to.
bool existsAsFile() const
Checks whether the file exists and is a file rather than a directory.
int64 getSize() const
Returns the size of the file in bytes.
const String & getFullPathName() const noexcept
Returns the complete, absolute path of this file.
File getChildFile(StringRef relativeOrAbsolutePath) const
Returns a file that represents a relative (or absolute) sub-path of the current one.
void readLines(StringArray &destLines) const
Reads the contents of this file as text and splits it into lines, which are appended to the given Str...
static File getCurrentWorkingDirectory()
Returns the current working directory.
@ tempDirectory
The folder that should be used for temporary files.
Result create() const
Creates an empty file if it doesn't already exist.
File getNonexistentChildFile(const String &prefix, const String &suffix, bool putNumbersInBrackets=true) const
Chooses a filename relative to this one that doesn't already exist.
static File JUCE_CALLTYPE getSpecialLocation(const SpecialLocationType type)
Finds the location of a special type of file or directory, such as a home folder or documents folder.
bool hasReadAccess() const
Checks whether a file can be read.
File getParentDirectory() const
Returns the directory that contains this file or directory.
String getVolumeLabel() const
Finds the name of the drive on which this file lives.
uint64 getFileIdentifier() const
Returns a unique identifier for the file, if one is available.
static juce_wchar getSeparatorChar()
The system-specific file separator character.
File()=default
Creates an (invalid) file object.
bool deleteFile() const
Deletes a file.
bool exists() const
Checks whether the file actually exists.
Automatically locks and unlocks a mutex object.
Very simple container class to hold a pointer to some data on the heap.
~InterProcessLock()
Destructor.
void exit()
Releases the lock if it's currently held by this process.
bool enter(int timeOutMillisecs=-1)
Attempts to lock the critical section.
InterProcessLock(const String &name)
Creates a lock object.
~MemoryMappedFile()
Destructor.
@ readWrite
Indicates that the memory can be read and written to - changes that are made will be flushed back to ...
@ readOnly
Indicates that the memory can only be read.
static void JUCE_CALLTYPE terminate()
Kills the current process immediately.
static bool setMaxNumberOfFileHandles(int maxNumberOfFiles) noexcept
UNIX ONLY - Attempts to use setrlimit to change the maximum number of file handles that the app can o...
static Random & getSystemRandom() noexcept
The overhead of creating a new Random object is fairly small, but if you want to avoid it,...
constexpr ValueType getStart() const noexcept
Returns the start of the range.
void setStart(const ValueType newStart) noexcept
Changes the start position of the range, leaving the end position unchanged.
constexpr ValueType getLength() const noexcept
Returns the length of the range.
Represents the 'success' or 'failure' of an operation, and holds an associated error message to descr...
static Result fail(const String &errorMessage) noexcept
Creates a 'failure' result.
A special array for holding a list of strings.
static StringArray fromTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Returns an array containing the tokens in a given string.
int size() const noexcept
Returns the number of strings in the array.
A simple class for holding temporary references to a string literal or String.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
const char * toRawUTF8() const
Returns a pointer to a UTF-8 version of this string.
bool containsChar(juce_wchar character) const noexcept
Tests whether the string contains a particular character.
static String toHexString(IntegerType number)
Returns a string representing this numeric value in hexadecimal.
static String fromUTF8(const char *utf8buffer, int bufferSizeBytes=-1)
Creates a String from a UTF-8 encoded buffer.
CharPointer_UTF8 toUTF8() const
Returns a pointer to a UTF-8 version of this string.
bool isNotEmpty() const noexcept
Returns true if the string contains at least one character.
static String getEnvironmentVariable(const String &name, const String &defaultValue)
Returns an environment variable.
static void JUCE_CALLTYPE setCurrentThreadAffinityMask(uint32 affinityMask)
Changes the affinity mask for the caller thread.
void * ThreadID
A value type used for thread IDs.
static void JUCE_CALLTYPE yield()
Yields the current thread's CPU time-slot and allows a new thread to run.
static ThreadID JUCE_CALLTYPE getCurrentThreadId()
Returns an id that identifies the caller thread.
static void JUCE_CALLTYPE setCurrentThreadName(const String &newThreadName)
Changes the name of the caller thread.
Priority
The different runtime priorities of non-realtime threads.
@ low
Uses efficiency cores when possible.
@ high
Makes use of performance cores and higher clocks.
@ background
Restricted to efficiency cores on platforms that have them.
@ highest
The highest possible priority that isn't a dedicated realtime thread.
static void JUCE_CALLTYPE sleep(int milliseconds)
Suspends the execution of the current thread until the specified timeout period has elapsed (note tha...
static int64 currentTimeMillis() noexcept
Returns the current system time.
#define JUCE_AUTORELEASEPOOL
A macro that can be used to easily declare a local ScopedAutoReleasePool object for RAII-based obj-C ...
void zerostruct(Type &structure) noexcept
Overwrites a structure or object with zeros.
int pointer_sized_int
A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
constexpr Type jmap(Type value0To1, Type targetRangeMin, Type targetRangeMax)
Remaps a normalised value (between 0 and 1) to a target range.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
unsigned long long uint64
A platform-independent 64-bit unsigned integer type.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
long long int64
A platform-independent 64-bit integer type.
pthread_attr_setschedparam
pthread_attr_setstacksize
pthread_mutexattr_settype
typedef pthread_mutexattr_t