Commit Graph

931 Commits

Author SHA1 Message Date
MacDue
62e8360dcf LibCore: Fix memory leak in Core::Process::spawn()
Previously the spawn_actions were not destroyed, which leaked a
little memory.
2023-03-24 22:06:38 +00:00
Cameron Youell
752f06f228 LibFileSystem: Move TempFile from LibCore to LibFileSystem
As suggested in commit de18485
2023-03-21 19:03:21 +00:00
Cameron Youell
492e5c3c14 LibCore: Remove all unused DeprecatedFile functions 2023-03-21 19:03:21 +00:00
Cameron Youell
e78be03b49 LibCore: Add ErrorOr wrapper for utimensat 2023-03-21 19:03:21 +00:00
Timothy Flynn
8a27180fb8 LibCore: Set tm_isdst to a negative value before invoking mktime
If it is default-initialized to 0, mktime will assume that DST is not in
effect for the specified time. Setting it to a negative value instructs
mktime to determine for itself whether DST is in effect.
2023-03-21 18:05:22 +00:00
Caoimhe
de18485a2f LibCore: Improve the TempFile wrapper
- We were using primitive versions of mkstemp and mkdtemp, they have
  been converted to use LibCore::System.
- If an error occurred whilst creating a temporary directory or file, it
  was thrown and the program would crash. Now, we use ErrorOr<T> so that
  the caller can handle the error accordingly
- The `Type` enumeration has been made private, and `create_temp` has
  been "split" (although rewritten) into create_temp_directory and
  create_temp_file. The old pattern of TempFile::create_temp(Type::File)
  felt a bit awkward, and TempFile::create_temp_file() feels a bit nicer
  to use! :^)

Once the Core::Filesystem PR is merged (#17789), it would be better for
this helper to be merged in with that. But until then, this is a nice
improvement.
2023-03-19 00:14:03 +00:00
Caoimhe
5072a2280d LibCore: Add syscall wrapper for mkdtemp() 2023-03-19 00:14:03 +00:00
kleines Filmröllchen
9ff01723ba Userland: Use more common WAV MIME type
There is no official IANA MIME type for WAV (see
https://www.iana.org/assignments/media-types/media-types.xhtml#audio),
so this will always be subjective. While
https://www.rfc-editor.org/rfc/rfc2361 suggests audio/vnd.wave, we use
audio/wav since that seems to be most common across the internet.
2023-03-17 22:20:16 +00:00
Karol Kosek
858e55b653 LibCore: Add new REGISTER_STRING_PROPERTY macro 2023-03-16 09:58:42 +01:00
Karol Kosek
ee5838084d LibCore+Userland: Add DEPRECATED infix to REGISTER_STRING_PROPERTY macro 2023-03-16 09:58:42 +01:00
Tim Schumacher
ae51c1821c Everywhere: Remove unintentional partial stream reads and writes 2023-03-13 15:16:20 +00:00
Tim Schumacher
ba354fa396 LibCore: Use length-checking stream reads and writes for SOCKS5 2023-03-13 15:16:20 +00:00
Tim Schumacher
a3f73e7d85 AK: Rename Stream::read_entire_buffer to Stream::read_until_filled
No functional changes.
2023-03-13 15:16:20 +00:00
Tim Schumacher
d5871f5717 AK: Rename Stream::{read,write} to Stream::{read_some,write_some}
Similar to POSIX read, the basic read and write functions of AK::Stream
do not have a lower limit of how much data they read or write (apart
from "none at all").

Rename the functions to "read some [data]" and "write some [data]" (with
"data" being omitted, since everything here is reading and writing data)
to make them sufficiently distinct from the functions that ensure to
use the entire buffer (which should be the go-to function for most
usages).

No functional changes, just a lot of new FIXMEs.
2023-03-13 15:16:20 +00:00
kleines Filmröllchen
8f4d0d3797 LibCore+Userland: Make Promise's on_resolve fallible
This will be primarily necessary for BackgroundAction integration, but
it already allows us to add proper error handling in LibIMAP :^)
2023-03-13 12:12:17 +00:00
kleines Filmröllchen
dc318d3080 LibCore: Add a constructor that sets the parent object 2023-03-13 12:12:17 +00:00
kleines Filmröllchen
30295bd988 LibCore: Allow EventLoop to manage and cancel promises
In this context, the promises are considered "jobs", and such jobs
depend in some way on the event loop. Therefore, they can be added to
the event loop, and the event loop will cancel all of its pending jobs
when it ends.
2023-03-13 12:12:17 +00:00
kleines Filmröllchen
bfd9f681f7 LibCore+Userland: Allow canceling promises
To make EventLoop cancel its managed Promises, we need the ability to
cancel them in the first place.
2023-03-13 12:12:17 +00:00
kleines Filmröllchen
afd0f941b7 LibCore: Add Promise to the forward declare header 2023-03-13 12:12:17 +00:00
Andreas Kling
a504ac3e2a Everywhere: Rename equals_ignoring_case => equals_ignoring_ascii_case
Let's make it clear that these functions deal with ASCII case only.
2023-03-10 13:15:44 +01:00
kleines Filmröllchen
61bb9103c2 Base+Userland: Add support for QOA files everywhere
This adds MIME type sniffing,
`file` support,
LaunchServer support to open QOA in SoundPlayer,
and audio icons
2023-03-10 04:07:14 -07:00
Linus Groh
e76394d96c AK: Remove infallible version of StringBuilder::to_byte_buffer
Also drop the try_ prefix from the fallible function, as it is no longer
needed to distinguish the two.
2023-03-09 15:51:00 +00:00
Karol Baraniecki
f8e94f2862 LibCore: Use fallible versions of StringBuilder::append in MimeData 2023-03-09 12:59:57 +00:00
Karol Baraniecki
68d3f348d9 LibCore: Use fallible version of StringBuilder::to_byte_buffer
... in MimeData.

This function isn't used anywhere, not sure if it's useful?
2023-03-09 12:59:57 +00:00
Andreas Kling
689ca370d4 Everywhere: Remove NonnullRefPtr.h includes 2023-03-06 23:46:35 +01:00
Andreas Kling
8a48246ed1 Everywhere: Stop using NonnullRefPtrVector
This class had slightly confusing semantics and the added weirdness
doesn't seem worth it just so we can say "." instead of "->" when
iterating over a vector of NNRPs.

This patch replaces NonnullRefPtrVector<T> with Vector<NNRP<T>>.
2023-03-06 23:46:35 +01:00
nipos
1a29ecd648 LibCore: Don't use DT_WHT in DirectoryEntry on OpenBSD 2023-03-06 12:53:01 +00:00
Sam Atkins
23aec16e8b LibCore: Introduce a new directory iteration API
`Core::Directory::for_each_entry()` takes a callback which is passed the
DirectoryEntry and the parent Directory. It returns any error from
creating the iterator, iterating the entries, or returned from the
callback.

As a simple example, this:

```c++
Core::DirIterator piece_set_iterator { "/res/icons/chess/sets/",
        Core::DirIterator::SkipParentAndBaseDir };
while (piece_set_iterator.has_next())
    m_piece_sets.append(piece_set_iterator.next_path());
```

becomes this:

```c++
TRY(Core::Directory::for_each_entry("/res/icons/chess/sets/"sv,
        Core::DirIterator::SkipParentAndBaseDir,
        [&](auto const& entry, auto&) -> ErrorOr<IterationDecision> {
    TRY(m_piece_sets.try_append(entry.name));
    return IterationDecision::Continue;
}));
```
2023-03-05 20:23:42 +01:00
Sam Atkins
ceaed7440e LibCore: Remove unused Directory::create_iterator() method 2023-03-05 20:23:42 +01:00
Sam Atkins
a4667fdc9b LibCore: Expose Directory file descriptor 2023-03-05 20:23:42 +01:00
Sam Atkins
7864898f52 LibCore: Ensure that Directory always has a path
`Directory::path()` returning `ErrorOr` makes it awkward to use, and all
current users create a Directory with a path. If we find we need
pathless directories later, we can come up with a clever solution
then. :^)
2023-03-05 20:23:42 +01:00
Sam Atkins
774f328783 LibCore+Everywhere: Return an Error from DirIterator::error()
This also removes DirIterator::error_string(), since the same strerror()
string will be included when you print the Error itself. Except in `ls`
which is still using fprintf() for now.
2023-03-05 20:23:42 +01:00
Sam Atkins
a98ae8f357 LibCore: Expose file type from DirIterator
Our `find` utility makes use of the `dirent::d_type` field for filtering
results, which `Core::DirIterator` didn't expose. So, now it does. :^)

We now store the name and type of the entry as the "next" value instead
of just the name. The type is exposed as a `DirectoryEntry::Type`
instead of a `DT_FOO` constant, so that we're not tied to posixy
systems, and because proper enums are nice. :^)
2023-03-05 20:23:42 +01:00
Liav A
11a7e21c2a Kernel+Userland: Add support for using the PCSpeaker with various tones 2023-03-05 08:38:29 +00:00
nipos
f8ed51e5dc LibCore: Add support for Solaris in anon_create 2023-03-04 21:34:54 -07:00
nipos
72accd3a24 LibCore: Don't use execvpe on Solaris 2023-03-04 21:34:54 -07:00
nipos
dcb95dba17 LibCore: Refer to type utsname as struct on Solaris 2023-03-04 21:34:54 -07:00
nipos
8687dae0ca LibCore: Use non-const char * for sethostname on Solaris 2023-03-04 21:34:54 -07:00
nipos
cdd1c8d0d9 LibCore: Implement socket credentials for Solaris 2023-03-04 21:34:54 -07:00
nipos
9139515aed LibCore: Include sys/filio.h for file-related ioctls on Solaris 2023-03-04 21:34:54 -07:00
nipos
50e663f561 LibCore: Use SIG_TYP instead of sig_t for signals on Solaris 2023-03-04 21:34:54 -07:00
Andreas Kling
d0977ac566 LibCore+LibGUI+About: Use String in Core::Version and GUI::AboutDialog
The Core::Version API now returns ErrorOr<String>, and the
GUI::AboutDialog API was adjusted to accommodate this.
2023-03-03 15:23:47 +01:00
Ali Mohammad Pur
23c514cda3 LibCore+Userland: Remove ArgsParser::add*(Vector<char const*>&)
This finally makes ArgsParser's value API free of silly char*'s!
2023-03-01 10:47:19 +01:00
Ali Mohammad Pur
500044906d LibCore+Everywhere: Remove ArgsParser::add*(char const*&)
This is not guaranteed to always work correctly as ArgsParser deals in
StringViews and might have a non-properly-null-terminated string as a
value. As a bonus, using StringView (and DeprecatedString where
necessary) leads to nicer looking code too :^)
2023-03-01 10:47:19 +01:00
Ali Mohammad Pur
db886fe18b Userland+AK: Stop using getopt() for ArgsParser
This commit moves the implementation of getopt into AK, and converts its
API to understand and use StringView instead of char*.
Everything else is caught in the crossfire of making
Option::accept_value() take a StringView instead of a char const*.

With this, we must now pass a Span<StringView> to ArgsParser::parse(),
applications using LibMain are unaffected, but anything not using that
or taking its own argc/argv has to construct a Vector<StringView> for
this method.
2023-02-28 15:52:24 +03:30
Ali Mohammad Pur
6e5ba82929 LibCore: Make ArgsParser tolerate Main::Arguments with only .strings
This currently allocates in .parse(), but that's better than making the
caller do the exact same before passing us the values.

Note that this is only temporary to aid in conversion, a future commit
will remove this and switch to requiring the users to allocate the
vector instead.
2023-02-28 15:52:24 +03:30
Andrew Kaster
72a48ee1ee LibCore+Utilities: Replace uses of strpbrk with find_any_of()
We don't need to use scary C string POSIX APIs when we have nicer ones
on String/DeprecatedString.
2023-02-25 22:31:17 +01:00
Linus Groh
09d40bfbb2 Everywhere: Use _{short_,}string to create Strings from literals 2023-02-25 20:51:49 +01:00
Nico Weber
f7e152d049 LibGfx: Add scaffolding for a webp decoder
At the moment, this processes the RIFF chunk structure and extracts
the ICCP chunk, so that `icc` can now print ICC profiles embedded
in webp files. (And are image files really more than containers
of icc profiles?)

It doesn't even decode image dimensions yet.

The lossy format is a VP8 video frame. Once we get to that, we
might want to move all the image decoders into a new LibImageDecoders
that depends on both LibGfx and LibVideo. (Other newer image formats
like heic and av1f also use video frames for image data.)
2023-02-24 19:44:20 +01:00
nipos
f700d553ab LibCore: Add support for NetBSD in anon_create 2023-02-20 18:46:51 +01:00
nipos
9a77934e23 LibCore: Enable file descriptor passing on all BSDs 2023-02-20 18:46:36 +01:00
nipos
b3aa36d7bd LibCore: All BSDs need sig_t instead of sighandler_t 2023-02-20 18:42:54 +01:00
nipos
d710da108c LibCore: Implement socket credentials for NetBSD 2023-02-20 18:42:29 +01:00
Lucas CHOLLET
5b6e93f96a LibCore: Add MappedFile::map_from_file()
This method relies on `map_from_fd_and_close()` but takes a `File`
instead of a fd.
2023-02-16 10:56:01 +00:00
Lucas CHOLLET
3a95c8111d LibCore: Allow MappedFile to make File leak its fd 2023-02-16 10:56:01 +00:00
Lucas CHOLLET
0f4a8731fd LibCore: Forward declare MappedFile 2023-02-16 10:56:01 +00:00
Tim Schumacher
43f98ac6e1 Everywhere: Remove the AK:: qualifier from Stream usages 2023-02-13 00:50:07 +00:00
Tim Schumacher
874c7bba28 LibCore: Remove Stream.h 2023-02-13 00:50:07 +00:00
Tim Schumacher
606a3982f3 LibCore: Move Stream-based file into the Core namespace 2023-02-13 00:50:07 +00:00
Tim Schumacher
a96339b72b LibCore: Move Stream-based sockets into the Core namespace 2023-02-13 00:50:07 +00:00
Tim Schumacher
d43a7eae54 LibCore: Rename File to DeprecatedFile
As usual, this removes many unused includes and moves used includes
further down the chain.
2023-02-13 00:50:07 +00:00
Liav A
b4596b48f5 LibCore: Fix wrong call to stat on the Core::System::lstat method
We should call lstat and not stat, because lstat gives information on
the symbolic link itself (if the path is about a symbolic link).
2023-02-10 23:23:12 +01:00
Timothy Flynn
4a916cd379 Everywhere: Remove needless copies of Error / ErrorOr instances
Either take the underlying objects with release_* methods or move() the
instances around.
2023-02-10 09:08:52 +00:00
Tim Schumacher
e8d5e938de AK: Remove the deprecated Stream implementation :^) 2023-02-08 19:18:26 +00:00
MacDue
63b11030f0 Everywhere: Use ReadonlySpan<T> instead of Span<T const> 2023-02-08 19:15:45 +00:00
Undefine
ccc871e608 LibCore: Propagate errors in SecretString 2023-02-08 19:49:48 +01:00
MacDue
b16ec1880c LibC+LibCore: Remove serenity_setenv()
This was called from LibCore and passed raw StringView data that may
not be null terminated, then incorrectly passed those strings to
getenv() and also tried printing them with just the %s format
specifier.
2023-02-05 16:40:51 +01:00
MacDue
eea4dc5bfe LibCore+LibC: Add putenv() wrapper
This is made safe with a special serenity_putenv() function in LibC.
2023-02-05 16:40:51 +01:00
MacDue
f4236e61bf LibCore: Add const qualifier to exec() argument spans 2023-02-05 16:40:51 +01:00
Tim Schumacher
371c51f934 AK: Make SeekableStream::truncate() take a size_t
Similar to the return values earlier, a signed value doesn't really make
sense here. Relying on the much more standard `size_t` makes it easier
to use Stream in all contexts.
2023-02-04 18:41:27 -07:00
Tim Schumacher
093cf428a3 AK: Move memory streams from LibCore 2023-01-29 19:16:44 -07:00
Tim Schumacher
2470dd3bb5 AK: Move bit streams from LibCore 2023-01-29 19:16:44 -07:00
Tim Schumacher
94f139c111 AK: Move buffered streams from LibCore 2023-01-29 19:16:44 -07:00
Tim Schumacher
8464da1439 AK: Move Stream and SeekableStream from LibCore
`Stream` will be qualified as `AK::Stream` until we remove the
`Core::Stream` namespace. `IODevice` now reuses the `SeekMode` that is
defined by `SeekableStream`, since defining its own would require us to
qualify it with `AK::SeekMode` everywhere.
2023-01-29 19:16:44 -07:00
Tim Schumacher
5f2ea31816 AK: Move Handle from LibCore and name it MaybeOwned
The new name should make it abundantly clear what it does.
2023-01-29 19:16:44 -07:00
Tim Schumacher
ae64b68717 AK: Deprecate the old AK::Stream
This also removes a few cases where the respective header wasn't
actually required to be included.
2023-01-29 19:16:44 -07:00
Linus Groh
108ea2b921 LibCore: Remove try_ prefix from fallible SharedCircularQueue methods 2023-01-28 22:41:36 +01:00
Linus Groh
9c08bb9555 AK: Remove try_ prefix from FixedArray creation functions 2023-01-28 22:41:36 +01:00
Linus Groh
6e7459322d AK: Remove StringBuilder::build() in favor of to_deprecated_string()
Having an alias function that only wraps another one is silly, and
keeping the more obvious name should flush out more uses of deprecated
strings.
No behavior change.
2023-01-27 20:38:49 +00:00
Sam Atkins
269ce258b4 LibCore: Replace uses of JsonObject::get_deprecated()/get_ptr() 2023-01-26 09:57:14 -05:00
Sam Atkins
00b897af8f LibCore: Add nice get/set_process_name() wrappers in Core::Process
`Process::get_name()` and `Process::set_name()` are basically the same
as `get_process_name()` and `set_process_name()`, except making use of
convenient Serenity standard types and returning ErrorOr, instead of
char* and errno shenanigans.

`Process::set_name()` has an optional `SetThreadName` parameter, for
when you also want to set the thread's name to the same thing. That's
true for the two places that use `set_process_name()`.
2023-01-25 14:27:45 +01:00
Karol Kosek
b810f7f88a LibCore: Implement File::can_delete_or_move()
Besides from a general check if a file's directory has write
permissions, this also checks if the directory has set a sticky bit,
meaning that only file owners and the directory owner can remove or move
files in such directory. It's being used in /tmp for example.
2023-01-24 20:13:30 +00:00
Tim Schumacher
6ccda76a71 LibCore: Add support for non-trivial types to Stream::*_value
At the moment, there is no immediate advantage compared to just calling
the underlying functions directly, but having a common interface feels
more ergonomic (users don't have to care about how a type serializes)
and maybe we'll find a way to hide the actual implementation from direct
access some time in the future.
2023-01-24 12:47:39 +00:00
Tim Schumacher
0245614a4f LibCore: Remove FileStream 2023-01-20 20:50:42 +00:00
Ali Mohammad Pur
7d4a30af56 LibCore: Avoid logical OOB read in AllocatingMemoryStream::offset_of()
The previous impl was trimming the last chunk to the free space instead
of the used space, which yielded an OOB read if the needle wasn't found.
2023-01-20 20:34:31 +00:00
Liav A
fedd18eb89 LibCore: Add MIME type string for TGA files 2023-01-20 15:13:31 +00:00
Liav A
e77b110541 LibCore: Return StringView from guess_mime_type_based_on_filename method 2023-01-20 15:13:31 +00:00
Timothy Flynn
0dce7b72f9 LibCore: Implement FileWatcher for macOS
The macOS FileWatcher depends on macOS dispatch queues, which run on a
different thread than the Core::EventLoop. This implementation handles
filesystem events on its dispatch queue, then forwards the event back to
the main Core::EventLoop for notifying the FileWatcher owner.
2023-01-19 11:29:48 +00:00
Timothy Flynn
0e7a48bd7d LibCore: Allow subclassing FileWatcher
This will be handy for platforms which need to be able to store extra
OS-specific members. For example, macOS needs to store a dispatch queue,
and event stream, etc.
2023-01-19 11:29:48 +00:00
Tim Schumacher
daf181caa8 LibCore: Let offset-related Stream functions return an unsigned value
A negative return value doesn't make sense for any of those functions.
The return types were inherited from POSIX, where they also need to have
an indicator for an error (negative values).
2023-01-19 11:41:56 +01:00
Tim Schumacher
1ca62de558 LibCore: Return EBADF on unsupported stream operations 2023-01-19 11:41:56 +01:00
Timothy Flynn
142abc0b2e LibCore+ConfigServer: Add FileWatcherFlags to replace InodeWatcherFlags
InodeWatcherFlags is an enumeration from the Kernel. To avoid using it
outside of Serenity, add a FileWatcherFlags for FileWatcher, much like
we already have FileWatcherEvent::Type.
2023-01-18 09:37:11 -05:00
Timothy Flynn
98e6dbf50a Userland: Add missing limits.h header includes
This is currently being implicitly including by InodeWatcherEvent.h by
way of FileWatcher.h. The former will soon be removed from the latter,
which would otherwise cause a compile error in these files.
2023-01-18 09:37:11 -05:00
Timothy Flynn
8ca528217c LibCore: Implement FileWatcher for Linux
This implements FileWatcher using inotify filesystem events. Serenity's
InodeWatcher is remarkably similar to inotify, so this is almost an
identical implementation.

The existing TestLibCoreFileWatcher test is added to Lagom (currently
just for Linux).

This does not implement BlockingFileWatcher as that is currently not
used anywhere but on Serenity.
2023-01-18 06:46:12 -05:00
Timothy Flynn
91cbdc67de LibCore: Default-initialize the FileWatcher event mask 2023-01-18 06:46:12 -05:00
Timothy Flynn
8419ca8b78 LibCore: Handle multiple events in the FileWatcher event mask formatter 2023-01-18 06:46:12 -05:00
Timothy Flynn
5bfc9daba1 LibCore: Move FileWatcher implementations into separate files
Rather than one big file with (eventually) all implementations for each
OS, let's keep OS-specific implementations in their own files.
2023-01-18 06:46:12 -05:00
Sam Atkins
1dd6b7f5b7 AK+Everywhere: Rename JsonObject::get() to ::get_deprecated()
This is a preparatory step to making `get()` return `ErrorOr`.
2023-01-17 19:52:52 -05:00
Tim Schumacher
0a563f4943 LibCore: Remove Stream::write_or_error
This was there for compatibility purposes and now it's no longer
needed.
2023-01-17 23:55:34 +01:00
Tim Schumacher
add2e2c076 LibCore: Do short forward seeks by discarding bytes from the buffer
This saves us an actual seek and rereading already stored buffer data in
cases where the seek is entirely covered by the currently buffered data.
This is especially important since we implement `discard` using `seek`
for seekable streams.
2023-01-17 21:56:56 +01:00
Tim Schumacher
bdf991fe76 LibCore: Calculate the correct seek offset for buffered streams 2023-01-17 21:56:56 +01:00
Lucas CHOLLET
2e52de5744 LibCore: Add Stream::File::fd()
Unlike `leak_fd()` the stream is still owning the file descriptor after
the call.
2023-01-16 17:05:41 +00:00
Tim Schumacher
d1711f1cef AK: Define our own concept of "trivially serializable"
While at it, rename the `read_trivial_value` and `write_trivial_value`
functions to `read_value` and `write_value` respectively, since we'll
add compatibility for non-trivial types down the line.
2023-01-15 23:06:31 -05:00
Tim Schumacher
6777cb0975 LibCore: Fix up type mistakes in Stream::read_trivial_value 2023-01-15 23:06:31 -05:00
nipos
bfacbe1e0d LibCore: Enable file descriptor passing on OpenBSD 2023-01-15 01:11:46 +00:00
Lucas CHOLLET
56512caa73 LibCore: Don't reject an empty buffer with ENOBUFS
Instead, we just return the empty buffer.
2023-01-14 16:20:30 -07:00
Lucas CHOLLET
4402720a15 LibCore: Don't rely on \n detection to populate the buffer
We don't need to call `can_read_line()` as the buffer will be populated
by `find_and_populate_until_any_of()`. The change is also beneficial as
the buffer will be populated until a candidate is found and not
necessarily a new line.
2023-01-14 16:20:30 -07:00
Lucas CHOLLET
8252436c18 LibCore: Resume search in find_and_populate_until_any_of
The search used to go through the buffer from the start, even if we just
appended a small number of bytes at the end. It now remembers the last
stop and resume the search from it.
2023-01-14 16:20:30 -07:00
Lucas CHOLLET
b21ea54af0 LibCore: Merge two search implementations in Stream::BufferedStream
`can_read_line()` and `read_until_any_of` used to have two different
implementations to search for a needle. This commit factorizes both
algorithms.
2023-01-14 16:20:30 -07:00
Lucas CHOLLET
9a7accddb7 AK: Add an optional starting offset to CircularBuffer::offset_of
This parameter allows to start searching after an offset. For example,
to resume a search.

It is unfortunately a breaking change in API so this patch also modifies
one user and one test.
2023-01-14 16:20:30 -07:00
nipos
b510747e22 LibCore: On OpenBSD, handle anon_create() like on MacOS 2023-01-14 16:31:59 +01:00
Tim Schumacher
202175cf4c LibCore: Add helper functions to read/write trivial values from streams
Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2023-01-13 18:41:05 -07:00
Niklas Poslovski
19bae983e4 LibCore: Enable file descriptor passing on FreeBSD
Ladybird currently doesn't render any webpages on FreeBSD and throws
hundreds of errors,beginning with this:
IPC::ConnectionBase (0x0000000805bf2b00) had an error (File descriptor
passing not supported on this platform), disconnecting.
WebContent process crashed!
2023-01-13 17:36:32 -07:00
Tim Schumacher
100112134d LibCore: Allow zero-sized spans in Stream::*_entire_buffer
There is no particular reason why we shouldn't allow zero-sized reads or
writes here, and this actually might cause issues with our common
stream-to-stream copy pattern if we end up at an unfortunate offset
where the next read would be zero-sized and trigger EOF only after that.
2023-01-13 17:34:45 -07:00
Tim Schumacher
156b6e83cd LibCore: Add AllocatingMemoryStream::offset_of 2023-01-14 00:33:35 +03:30
Arda Cinar
3f99a8734e LibCore: Call the mkstemp function in a slightly prettier way
This removes a FIXME, although the new version isn't less char-pointery.
2023-01-13 09:29:44 -05:00
Sam Atkins
6edc0cf5ab LibCore+Userland: Don't auto-start new Core::Timers
This was unintuitive, and only useful in a few cases. In the majority,
users had to immediately call `stop()`, and several who did want the
timer started would call `start()` on it immediately anyway. Case in
point: There are only two places I had to add a manual `start()`.
2023-01-12 11:25:51 +01:00
Sam Atkins
a8cf0c9371 LibCore+Userland: Make Core::Timer::create_single_shot() return ErrorOr
clang-format sure has some interesting opinions about where to put a
method call that comes after a lambda. :thonk:
2023-01-12 11:25:51 +01:00
Sam Atkins
a15d44f019 LibCore+Userland: Make Core::Timer::create_repeating() return ErrorOr
The FIXMEs must flow!
2023-01-12 11:25:51 +01:00
Linus Groh
c5cadca542 LibCore: Add StandardPaths::font_directories()
This provides a list of well-known directories containing font files,
e.g. for use with Gfx::FontDatabase::load_all_fonts_from_path().
2023-01-11 20:54:49 +00:00
kleines Filmröllchen
2475f6a641 LibCore: Explain EventLoop and reorder some members in the header
This hopefully makes EventLoop easier to understand.
2023-01-11 11:49:05 +01:00
Andreas Kling
5dcc58d54a Kernel+LibCore: Make %sid path parsing not take ages
Before this patch, Core::SessionManagement::parse_path_with_sid() would
figure out the root session ID by sifting through /sys/kernel/processes.

That file can take quite a while to generate (sometimes up to 40ms on my
machine, which is a problem on its own!) and with no caching, many of
our programs were effectively doing this multiple times on startup when
unveiling something in /tmp/session/%sid/

While we should find ways to make generating /sys/kernel/processes fast
again, this patch addresses the specific problem by introducing a new
syscall: sys$get_root_session_id(). This extracts the root session ID
by looking directly at the process table and takes <1ms instead of 40ms.

This cuts WebContent process startup time by ~100ms on my machine. :^)
2023-01-10 19:32:31 +01:00
Tim Schumacher
b4b80b7ec6 LibCore: Add {Big,Little}EndianOutputBitStream
Also add some tests that ensure that the input and output streams match
each other, because I can't wrap my head around what the internal
representation looks like.
2023-01-10 10:28:26 +01:00
Tim Schumacher
0bdbe27d6b LibCore: Rename InputBitStream.h to BitStream.h
We won't just be defining readable streams here from now on, but also
writable streams.
2023-01-10 10:28:26 +01:00
Nico Weber
e5988b4a0d LibCore: Teach MimeData about ICC file extension and contents
See https://www.color.org/profile_embedding.xalter and
https://www.iana.org/assignments/media-types/application/vnd.iccprofile
for mime type and extensions.

See LibGfx/ICCProfile.cpp, parse_file_signature() for the magic number.
2023-01-08 13:25:15 +01:00
Andrew Kaster
4afa6e264c LibCore+LibWeb: Use AK::Time instead of timeval in Core::ElapsedTimer
This removes the direct dependency on sys/time.h from ElapsedTimer, and
makes the code a lot cleaner by using the helpers from AK::Time for
time math and getting the current timestamp.
2023-01-07 14:51:04 +01:00
Karol Kosek
4f699d0f58 LibCore: Add forward declaration for Core::Stream::File 2023-01-07 10:53:43 +00:00
Lucas CHOLLET
f0d2a8dd57 LibCore: Add Stream::File::leak_fd(Badge<IPC::File>) 2023-01-06 14:52:29 +00:00
Timothy Flynn
ab99ed5fba LibIPC+Everywhere: Change IPC::encode's return type to ErrorOr
In doing so, this removes all uses of the Encoder's stream operator,
except for where it is currently still used in the generated IPC code.
So the stream operator currently discards any errors, which is the
existing behavior. A subsequent commit will propagate the errors.
2023-01-04 11:49:15 +01:00
Tim Schumacher
dd948b046c LibCore: Add Stream::WrapInAKOutputStream 2023-01-03 10:01:09 +00:00
Ben Wiederhake
6b7ce19161 Everywhere: Remove unused includes of LibC/stdlib.h
These instances were detected by searching for files that include
stdlib.h, but don't match the regex:

\\b(_abort|abort|abs|aligned_alloc|arc4random|arc4random_buf|arc4random_
uniform|atexit|atof|atoi|atol|atoll|bsearch|calloc|clearenv|div|div_t|ex
it|_Exit|EXIT_FAILURE|EXIT_SUCCESS|free|getenv|getprogname|grantpt|labs|
ldiv|ldiv_t|llabs|lldiv|lldiv_t|malloc|malloc_good_size|malloc_size|mble
n|mbstowcs|mbtowc|mkdtemp|mkstemp|mkstemps|mktemp|posix_memalign|posix_o
penpt|ptsname|ptsname_r|putenv|qsort|qsort_r|rand|RAND_MAX|random|reallo
c|realpath|secure_getenv|serenity_dump_malloc_stats|serenity_setenv|sete
nv|setprogname|srand|srandom|strtod|strtof|strtol|strtold|strtoll|strtou
l|strtoull|system|unlockpt|unsetenv|wcstombs|wctomb)\\b

(Without the linebreaks.)

This regex is pessimistic, so there might be more files that don't
actually use anything from the stdlib.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:27:20 -05:00
Ben Wiederhake
b2cd935efd LibCore: Remove unused include MemMem
These instances were detected by searching for files that include
MemMem.h, but don't match the regex:
\\b(MemMem(?!\.h>)|bitap_bitwise|memmem|memmem_optional)\\b
These are the only symbols defined by MemMem.h.

In theory, one might use LibCPP to detect things like this
automatically, but let's do this one step after another.
2023-01-02 20:08:35 +00:00
Ben Wiederhake
b83cb09db1 Everywhere: Fix badly-formatted includes
In 7c5e30daaa, the focus was "only" on
Userland/Libraries/, whereas this commit cleans up the remaining
headers in the repo, and any new badly-formatted include.
2023-01-02 11:06:15 -05:00
Sam Atkins
b32f5dbcff LibCore+LibGUI: Add fallible versions of Widget::load_from_gml()
The existing `load_from_gml()` methods look the same as before from the
outside. Inside though, they now forward to `try_load_from_gml()` which
returns Error when things go wrong. It also now calls the `try_create()`
factory method for Objects instead of the `construct()` one.
2023-01-01 09:55:05 -05:00
Ben Wiederhake
e8ce0f0eba LibCore: Make DateTime more easily debuggable
In particular, implement operator== and AK::Formatter.
2022-12-31 23:21:17 +01:00
Lucas CHOLLET
bf06f49417 LibCore: Use CircularBuffer in BufferedHelper
This patch takes care of a FIXME :^)

Co-Authored-By: Tim Schumacher <timschumi@gmx.de>
2022-12-31 04:44:17 -07:00
Lucas CHOLLET
945d2079b4 LibCore: Add a deleted state for Account
As other setters, this only affect the in-memory copy, you need to call
`sync()` to apply changes.
2022-12-31 04:24:05 -07:00
Lucas CHOLLET
f000193ee5 LibCore: Deduplicate some code in Account::generate_shadow_file() 2022-12-31 04:24:05 -07:00
Timothy Flynn
9b483625e6 LibIPC+Everywhere: Change IPC decoders to construct values in-place
Currently, the generated IPC decoders will default-construct the type to
be decoded, then pass that value by reference to the concrete decoder.
This, of course, requires that the type is default-constructible. This
was an issue for decoding Variants, which had to require the first type
in the Variant list is Empty, to ensure it is default constructible.

Further, this made it possible for values to become uninitialized in
user-defined decoders.

This patch makes the decoder interface such that the concrete decoders
themselves contruct the decoded type upon return from the decoder. To do
so, the default decoders in IPC::Decoder had to be moved to the IPC
namespace scope, as these decoders are now specializations instead of
overloaded methods (C++ requires specializations to be in a namespace
scope).
2022-12-26 09:36:16 +01:00
Timothy Flynn
69beda23c3 LibConfig+LibCore+ConfigServer: Support u32 configuration entries 2022-12-23 23:26:21 +01:00
Tim Schumacher
8455d58a44 LibCore: Use a StringView for the file path in File::remove
This allows us to use our nice syscall wrappers, avoids some accidental
string copying, and starts to unlink us from the old DeprecatedString.
2022-12-23 10:38:14 -05:00
Tim Schumacher
9805f73704 LibCore: Remove the force parameter from File::remove
About half of the usages were not using `force` anyways, and the other
half presumably just got confused about what "force" really means in
this context (which is "ignore nonexistent files").

The only 'legitimate' user, which is `rm`, instead now handles this
completely internally instead.
2022-12-23 10:38:14 -05:00
Tim Schumacher
355e761a02 LibCore: Let File::remove return a normal ErrorOr
Having the file path in there is nice, but it makes us incompatible with
comfortable error propagation in everything that isn't File::remove.
2022-12-23 10:38:14 -05:00
Alexander Narsudinov
767529ebf5 LibCore: Make UDPServer::receive() return ErrorOr<ByteBuffer>
This is a first step towards handling OOM errors instead of just
crashing the program.

Now UDPServer's method `receive()` return memory allocation
errors explicitly with help of ErrorOr.

This removes one FIXME and make a bunch of new ones. :(
2022-12-20 10:45:20 +01:00
Jelle Raaijmakers
25f2e4981c AK: Stop using DeprecatedString in Base64 encoding 2022-12-20 10:34:19 +01:00
Jelle Raaijmakers
9feac465dc LibCore: Convert explicit timezone to local in DateTime::parse
When we encounter an explicit timezone, we shift the time to UTC.
Because we rely on `mktime`, we need to shift it to the local time
before proceeding. If no explicit timezone is provided, local timezone
is assumed.

This fixes the "timezone-offset extension" LibJS test running on
machines with a non-UTC timezone offset.

Co-authored-by: Timothy Flynn <trflynn89@pm.me>
2022-12-19 07:07:49 -05:00
Lenny Maiorani
f2336d0144 AK+Everywhere: Move custom deleter capability to OwnPtr
`OwnPtrWithCustomDeleter` was a decorator which provided the ability
to add a custom deleter to `OwnPtr` by wrapping and taking the deleter
as a run-time argument to the constructor. This solution means that no
additional space is needed for the `OwnPtr` because it doesn't need to
store a pointer to the deleter, but comes at the cost of having an
extra type that stores a pointer for every instance.

This logic is moved directly into `OwnPtr` by adding a template
argument that is defaulted to the default deleter for the type. This
means that the type itself stores the pointer to the deleter instead
of every instance and adds some type safety by encoding the deleter in
the type itself instead of taking a run-time argument.
2022-12-17 16:00:08 -05:00
Federico Guerinoni
43ff500a80 LibCore: Use ';' to split socket path in SOCKET_TAKEOVER
This allow to use socket path with spaces inside.

Closes #16436.
2022-12-15 12:33:36 -05:00
Timothy Flynn
701e77019c LibCore: Use the user's root session ID for standard runtime path
This ensures processes created by the user use the same runtime path.
2022-12-15 17:29:19 +00:00
Lucas CHOLLET
048d0a9870 LibCore: Use System::getaddrinfo() in Socket::resolve_host 2022-12-15 13:38:13 +00:00
Lucas CHOLLET
687ef7740a LibCore: Add a wrapper for getaddrinfo() 2022-12-15 13:38:13 +00:00
Tim Schumacher
6640cb57b3 LibCore: Use AllocatingMemoryStream for SOCKSProxyClient 2022-12-15 13:28:29 +00:00
Tim Schumacher
f205f62a44 LibCore: Add an automatically allocating MemoryStream
Similar to AK::DuplexStream, this writes to the end and reads from the
beginning of a dynamically allocated buffer.
2022-12-15 13:28:29 +00:00
Tim Schumacher
8dbc7aa63f LibCore: Move the MemoryStream implementation into a separate file 2022-12-15 13:28:29 +00:00
Tim Schumacher
c6d71ca727 LibCore: Rename MemoryStream to FixedMemoryStream
This is to differentiate between the upcoming `AllocatingMemoryStream`,
which automatically allocates memory as needed instead of operating on a
static memory area.
2022-12-15 13:28:29 +00:00
Lucas CHOLLET
cfb0e1bdb2 LibCore: Add fd overload of File::is_directory and File::is_device 2022-12-14 18:26:25 +00:00
Timothy Flynn
e305b32d9a LibCore: Protect Core::Group against null group::gr_mem members
Serenity's implementation does not set this pointer to anything, so we
should not assume it was set.
2022-12-14 07:25:36 -05:00
Timothy Flynn
d09266237d LibCore: Define and use a fallible, OS-independent getgrent(_r) wrapper
Rather than maintaining a list of #ifdef guards to check systems that do
not provide the reentrant version of getgrent, we can use C++ concepts
to let the compiler perform this check for us.

While we're at it, we can also provide this wrapper as fallible to let
the caller TRY calling it.
2022-12-14 07:25:36 -05:00
Timothy Flynn
1ee808fae6 LibCore: Define and use a fallible, OS-independent getpwent(_r) wrapper
Rather than maintaining a list of #ifdef guards to check systems that do
not provide the reentrant version of getpwent, we can use C++ concepts
to let the compiler perform this check for us.

While we're at it, we can also provide this wrapper as fallible to let
the caller TRY calling it.
2022-12-14 07:25:36 -05:00
Ali Mohammad Pur
f96a3c002a Everywhere: Stop shoving things into ::std and mentioning them as such
Note that this still keeps the old behaviour of putting things in std by
default on serenity so the tools can be happy, but if USING_AK_GLOBALLY
is unset, AK behaves like a good citizen and doesn't try to put things
in the ::std namespace.

std::nothrow_t and its friends get to stay because I'm being told that
compilers assume things about them and I can't yeet them into a
different namespace...for now.
2022-12-14 11:44:32 +01:00
Drew DeVault
c7f8d74c1c LibCore: Fix struct msghdr initialization
The previous approach could leave behind uninitialized fields on
platforms which have additional fields in this structure (e.g. padding
fields on musl libc).
2022-12-13 10:12:59 -08:00
Tim Schumacher
f909cfbe75 LibCore: Use the new Handle type for the BitStream types
This allows us to either pass a reference, which keeps compatibility
with old code, or to pass a NonnullOwnPtr, which allows us to
comfortably chain streams as usual.
2022-12-12 16:21:39 +00:00
Tim Schumacher
8b5df161af LibCore: Add Stream::Handle
This essentially wraps a `NonnullOwnPtr` or a reference, allowing us to
either have a stream own a dependent stream that it uses or to just hold
a reference if a stream is already owned by somebody else and we just
want to use it temporarily.
2022-12-12 16:21:39 +00:00
Lucas CHOLLET
3750687821 LibCore: Use Core::System::poll() in PosixSocketHelper 2022-12-12 16:14:11 +00:00
Lucas CHOLLET
5532640b71 LibCore: Add a wrapper for poll() 2022-12-12 16:14:11 +00:00
Tim Schumacher
3fccf2481c LibCore: Make not discarding all requested bytes from a stream an error 2022-12-12 14:16:42 +01:00
Tim Schumacher
9a3e95785e LibCore: Propagate errors from Stream::*_entire_buffer 2022-12-12 14:16:42 +01:00
Tim Schumacher
6c7c5a6786 LibCore: Rename Stream::*_or_error to *_entire_buffer
All of our functions are `_or_error` (or are about to be), and maybe
making it less reminiscient of AK::Stream will make people use it more.
2022-12-12 14:16:42 +01:00
Tim Schumacher
ed4c2f2f8e LibCore: Rename Stream::read_all to read_until_eof
This generally seems like a better name, especially if we somehow also
need a better name for "read the entire buffer, but not the entire file"
somewhere down the line.
2022-12-12 14:16:42 +01:00
Tim Schumacher
5061a905ff LibCore: Remove Stream::is_{readable,writable}
Next to functions like `is_eof` these were really confusing to use, and
the `read`/`write` functions should fail anyways if a stream is not
readable/writable.
2022-12-12 14:16:42 +01:00
sin-ack
2a502fe232 Kernel+LibC+LibCore+UserspaceEmulator: Implement faccessat(2)
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
2022-12-11 19:55:37 -07:00
sin-ack
d5fbdf1866 Kernel+LibC+LibCore: Implement renameat(2)
Now with the ability to specify different bases for the old and new
paths.
2022-12-11 19:55:37 -07:00
sin-ack
eb5389e933 Kernel+LibC+LibCore: Implement mkdirat(2) 2022-12-11 19:55:37 -07:00
sin-ack
6445a706cf Kernel+LibC: Implement readlinkat(2)
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
2022-12-11 19:55:37 -07:00
sin-ack
9850a69cd1 Kernel+LibC+LibCore: Implement symlinkat(2)
Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
2022-12-11 19:55:37 -07:00
Timothy Flynn
c46c3555a1 LibCore: Add a standard path for runtime communication files
This corresponds to XDG_RUNTIME_DIR, which is the path applications may
place runtime communication files, like local sockets.
2022-12-11 10:08:17 -05:00
Tim Schumacher
4e7da96d58 LibCore: Add a wrapper for adapting Core::Stream to AK::InputStream 2022-12-10 12:05:55 +00:00
Tim Schumacher
8940f2da7f LibCore: Use Core::Stream for ProcessStatisticsReader 2022-12-10 11:49:24 +00:00
Moustafa Raafat
ae2abcebbb Everywhere: Use C++ concepts instead of requires clauses 2022-12-09 11:25:30 +00:00
Timothy Flynn
746364d7c1 LibCore: Support write-only Object properties
Some properties are set and then never retrieved, e.g. GUI icon paths.
Add a helper to create such properties, similar to the read-only helper.
2022-12-09 00:05:30 +01:00
Timothy Flynn
49d74ee288 LibCore: Add a standard path for application data 2022-12-08 17:14:48 +01:00
Timothy Flynn
4609477ac0 LibCore: Support XDG_CONFIG_HOME when determing the user's config path
And default to a path commonly used depending on the operating system.
2022-12-08 17:14:48 +01:00
Tim Schumacher
2fc2025f49 LibCore: Move Core::Stream::File::exists() to Core::File
`Core::Stream::File` shouldn't hold any utility methods that are
unrelated to constructing a `Core::Stream`, so let's just replace the
existing `Core::File::exists` with the nicer looking implementation.
2022-12-08 12:52:14 +00:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Linus Groh
babfc13c84 Everywhere: Remove 'clang-format off' comments that are no longer needed
https://github.com/SerenityOS/serenity/pull/15654#issuecomment-1322554496
2022-12-03 23:52:23 +00:00
Linus Groh
d26aabff04 Everywhere: Run clang-format 2022-12-03 23:52:23 +00:00
Sam Atkins
0fc673e759 LibCore: Mark connections to InspectorServer as MSG_NOSIGNAL
If InspectorServer closes for some reason at the wrong time, there is no
need for the inspected application to terminate.
2022-12-03 14:27:05 +01:00
Sam Atkins
9eb26ddd21 LibCore: Mark LocalServer client sockets as MSG_NOSIGNAL
Make LocalServer connections not terminate their process from SIGPIPE,
which fixes the issue where closing DisplaySettings with the[OK] button
would often crash WindowServer.
2022-12-03 14:27:05 +01:00
Sam Atkins
cb5f83606a LibCore: Optionally pass MSG_NOSIGNAL to socket read/writes
When creating a `Core::Stream::Socket`, you can now choose to prevent
SIGPIPE signals from firing and terminating your process. This is done
by passing MSG_NOSIGNAL to the `System::recv()` or `System::send()`
calls when you `read()` or `write()` to that Socket.
2022-12-03 14:27:05 +01:00
Tim Schumacher
d402f6cdb3 LibCore: Add support for ReadonlyBytes to MemoryStream 2022-11-30 12:09:53 +00:00
Tim Schumacher
6e29619dcb LibCore: Add Stream::discard() 2022-11-30 08:03:31 +01:00
Tim Schumacher
7a065513cd LibCore: Add a basic wrapper for adapting AK::Stream to Core::Stream 2022-11-30 08:03:31 +01:00
Andreas Kling
c8ff2184bd LibCore: Add Core::System::posix_fallocate() 2022-11-29 11:09:19 +01:00
thankyouverycool
63d0aa9d8a LibCore: Add %l conversion specification to DateTime
Replaced by the hour as a decimal 1-12 in which single digits
are preceded by a blank
2022-11-28 13:12:08 +01:00
Liav A
7d7127b463 LibCore: Add add_option aggregating the same option multiple times
This could be used in a scenario when it is expected that a user program
will be invoked with a specific option multiple times, for example:
"program --a-option=example --a-option=anotherexample ..."
2022-11-26 12:42:15 -07:00
Liav A
718ae68621 Kernel+LibCore+LibC: Implement support for forcing unveil on exec
To accomplish this, we add another VeilState which is called
LockedInherited. The idea is to apply exec unveil data, similar to
execpromises of the pledge syscall, on the current exec'ed program
during the execve sequence. When applying the forced unveil data, the
veil state is set to be locked but the special state of LockedInherited
ensures that if the new program tries to unveil paths, the request will
silently be ignored, so the program will continue running without
receiving an error, but is still can only use the paths that were
unveiled before the exec syscall. This in turn, allows us to use the
unveil syscall with a special utility to sandbox other userland programs
in terms of what is visible to them on the filesystem, and is usable on
both programs that use or don't use the unveil syscall in their code.
2022-11-26 12:42:15 -07:00
Ali Mohammad Pur
2110e7cf85 Everywhere: Add support for compilation under emscripten
Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2022-11-26 02:23:15 +03:30
ne0ndrag0n
d8f25ad644 LibCore: Sync groups, getgrent to getgrent_r, fix gr_mem bug 2022-11-25 23:13:16 +01:00
kleines Filmröllchen
4777dc75c5 LibCore: Allow array-like rectangle specifications for rect properties
This allows rectangle specifications in the form [x, y, width, height],
which mirrors margin properties and is much more convenient than the
JSON object specifications that were allowed before. Those are still
allowed, of course.
2022-11-25 14:28:33 -07:00