Commit Graph

416 Commits

Author SHA1 Message Date
Koakuma 5dd6f9616e Fix linux dirent64 buffer align directive 2021-05-12 14:52:53 +07:00
Andrew Kelley a008fb0a71 std.fs: delete unused label
stage2 starting to catch problems with the standard library :)
2021-04-20 17:57:35 -07:00
Andrew Kelley 429cd2b5dd std: change @import("builtin") to std.builtin 2021-04-15 19:06:39 -07:00
Frank Denis b8c019ef49 std/base64: cleanups & support url-safe and other non-padded variants
This makes a few changes to the base64 codecs.

* The padding character is optional. The common "URL-safe" variant, in
particular, is generally not used with padding. This is also the case for
password hashes, so having this will avoid code duplication with bcrypt,
scrypt and other functions.
* The URL-safe variant is added. Instead of having individual constants
for each parameter of each variant, we are now grouping these in a
struct. So, `standard_pad_char` just becomes `standard.pad_char`.
* Types are not `snake_case`'d any more. So, `standard_encoder` becomes
`standard.Encoder`, as it is a type.
* Creating a decoder with ignored characters required the alphabet and
padding. Now, `standard.decoderWithIgnore(<ignored chars>)` returns a
decoder with the standard parameters and the set of ignored chars.
* Whatever applies to `standard.*` obviously also works with `url_safe.*`
* the `calcSize()` interface was inconsistent, taking a length in the
encoder, and a slice in the encoder. Rename the variant that takes a
slice to `calcSizeForSlice()`.
* In the decoder with ignored characters, add `calcSizeUpperBound()`,
which is more useful than the one that takes a slice in order to size
a fixed buffer before we have the data.
* Return `error.InvalidCharacter` when the input actually contains
characters that are neither padding nor part of the alphabet. If we
hit a padding issue (which includes extra bits at the end),
consistently return `error.InvalidPadding`.
* Don't keep the `char_in_alphabet` array permanently in a decoder;
it is only required for sanity checks during initialization.
* Tests are unchanged, but now cover both the standard (padded) and
the url-safe (non-padded) variants.
* Add an error set, rename `OutputTooSmallError` to `NoSpaceLeft`
to match the `hex2bin` equivalent.
2021-03-28 14:32:34 +02:00
Al Hoang c17396691c initial support for haiku sync update
* add cpu count
* use haiku find_directory
* add definitions and exports for building in haiku
2021-02-25 16:41:42 -07:00
Al Hoang 6b0372229d initial support for haiku continue clean up
* remove unused definitions
* setup os specific blocks
2021-02-25 16:41:42 -07:00
Al Hoang 025635c3f8 initial support for haiku past stage0 2021-02-25 16:41:42 -07:00
Benjamin Graf c70832bc41 replace ArrayList.shrinkAndFree by ArrayList.shrinkRetainingCapacity 2021-02-21 11:56:14 +02:00
LemonBoy 134f5fd3d6 std: Update test "" to test where it makes sense 2021-01-22 15:46:58 +01:00
Alex Cameron 89286376c6 std: Rename ArrayList shrink => shrinkAndFree 2021-01-06 00:55:51 +11:00
Andrew Kelley 99203e4177 Merge pull request #7578 from vrischmann/walker
fix segfault in std.fs.Walker
2021-01-01 13:28:01 -08:00
Frank Denis 6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
Vincent Rischmann 9c53564af1 fs: fix segfault in Walker.next
`top` might point to invalid memory after a call to self.stack.append
which causes a segfault.

Prevent this by recomputing `top`.

Fixes #7560
2020-12-28 18:14:27 +01:00
frmdstryr 577b57784a Return encoded slice from base64 encode 2020-12-24 01:27:21 +02:00
Andrew Kelley 013efaf139 std: introduce a thread-local CSPRNG for general use
std.crypto.random

* cross platform, even freestanding
* can't fail. on initialization for some systems requires calling
  os.getrandom(), in which case there are rare but theoretically
  possible errors. The code panics in these cases, however the
  application may choose to override the default seed function and then
  handle the failure another way.
* thread-safe
* supports the full Random interface
* cryptographically secure
* no syscall required to initialize on Linux (AT_RANDOM)
* calls arc4random on systems that support it

`std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`.

I moved some of the Random implementations into their own files in the
interest of organization.

stage2 no longer requires passing a RNG; instead it uses this API.

Closes #6704
2020-12-18 12:22:46 -07:00
Mathieu Guay-Paquet 4c8632e244 fix the tinyest typo 2020-12-02 19:08:25 +02:00
Jonathan Marler 48660371a2 std.meta: add assumeSentinel 2020-11-29 10:36:02 -08:00
LemonBoy 8ed7561422 std: Re-enable the use of O_EXLOCK/O_SHLOCK on macos 2020-11-24 10:23:54 +01:00
LemonBoy 26d20e39fc std: Close dangling fd on error
This patch was already submitted for openFileZ, createFileZ was left
unpatched.
2020-11-23 18:00:05 +01:00
LemonBoy 0d4f05bb8a std: Remove O_NONBLOCK flag after locking
We only need O_NONBLOCK when O_SHLOCK/O_EXLOCK are used and we don't
want open() to block, don't let this bit leak to the user fd.
2020-11-23 18:00:05 +01:00
LemonBoy f8ddc3d873 std: Fix file locking logic for BSD targets 2020-11-23 18:00:05 +01:00
Sébastien Marie b174942e6a openbsd, netbsd: getdents: entry with d_fileno==0 should be skipped 2020-11-19 13:55:46 +00:00
Sébastien Marie 7579ce180f Iterator: rename freebsd_entry to bsd_entry to reflect that nextBsd is not freebsd only 2020-11-19 13:54:47 +00:00
Sébastien Marie ad2ff9e65d darwin: getdents: entry with d_ino==0 should be skipped 2020-11-19 13:54:29 +00:00
Veikka Tuominen 6d5b76a75d Merge pull request #7005 from jshholland/deprecate-span
Remove ArrayList.span
2020-11-18 13:14:48 +02:00
g-w1 a0226ab05b std: openDirAbsolute and accessAbsolute (#7082)
* add more abosolutes

* added wrong files

* adding 2 tests and changing the function signatures because of lazy analysis not checking them

* fix a bug that got uncovered by lazy eval

* Add compile error when using WASI with openDirAbsolute and accessAbsolute

* typo
2020-11-18 08:42:35 +01:00
Josh Holland c25b157dda remove deprecated uses of ArrayList.span 2020-11-07 11:15:44 +00:00
Alex Cameron ecdd636605 Fix file descriptor leak in fs.openFileZ. 2020-11-02 13:28:29 -05:00
Sébastien Marie 3115d2f2cd readd original code from #6638. realpathZ() is expected to take a [*:0]const u8 2020-10-25 10:02:10 +01:00
Andrew Kelley 05b1a7414e code cleanups
* in selfExePath, return errors instead of defaulting to bogus data
 * less invasive edits to the logic of link/Elf.zig
 * less indentation
2020-10-17 17:52:09 -07:00
Sebastien Marie 35a7247a2c Merge branch 'master' into openbsd-minimal 2020-10-17 17:38:23 +02:00
Vignesh Rajagopalan 2ab0c7391a Rename .macosx to .macos 2020-10-12 18:56:25 -04:00
Sébastien Marie a6dc2b7fcc openbsd: selfExePath adjustements 2020-10-11 12:23:52 +00:00
Sébastien Marie 97ec9fdd79 opensd: selfExePath: do not rely on environment as it could be inherited 2020-10-11 08:23:37 +00:00
Sébastien Marie 78a7543056 openbsd: use mem.span() + mem.indexOf() instead of defining custom function 2020-10-11 08:23:37 +00:00
Sébastien Marie f33a610c84 add minimal openbsd support 2020-10-11 08:23:36 +00:00
Andrew Kelley 9f8f446435 fixups to previous commit
* std.fs.Dir.readFile: add doc comments to explain what it means when
   the returned slice has the same length as the supplied buffer.
 * introduce readSmallFile / writeSmallFile to abstract over the
   decision to use symlink or file contents to store data.
2020-10-09 16:45:39 -07:00
mlarouche 57912964af Use regular file for caching stage 1 hash digest instead of symlink, fix zig build caching on Windows
Fix #6500
2020-10-09 16:50:43 -04:00
Andrew Kelley 76a195473d Merge pull request #6516 from LemonBoy/fastfilecopy
std: Make file copy ops use zero-copy mechanisms
2020-10-08 20:14:47 -04:00
LemonBoy 03762da2af New review round 2020-10-07 11:13:26 +02:00
LemonBoy 1f7ec0de70 Address review comments & fix compilation errors 2020-10-06 11:57:23 +02:00
LemonBoy a419a1aabc Move copy_file to fs namespace
Now it is a private API.
Also handle short writes in copy_file_range fallback implementation.
2020-10-06 09:38:59 +02:00
Noah Altunian c507c7862e Fix spelling in code comment
Changed **an handle** -> **a handle**.
2020-10-05 22:25:07 -04:00
LemonBoy 8b4f5f039d Alternative strategy to avoid calling stat()
This is an optimization as it avoids an extra syscall, but it's also a
workaround for fstat being not available on Windows.
2020-10-03 19:51:22 +02:00
LemonBoy 0f248e0988 std: Make file copy ops use zero-copy mechanisms
Use copy_file_range on Linux (if available), fcopyfile on Darwin,
sendfile on *BSDs (and on Linux kernels without copy_file_range).
2020-10-03 12:31:17 +02:00
Loris Cro 276598346a provide the full buffer length to _NSGetExecutablePath
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-03 12:03:22 +02:00
Loris Cro f841ea77e2 make symlink buffer null-terminated
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-02 19:33:14 +02:00
Loris Cro a2074c1ec3 fix symlink path not being resolved in darwin
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-02 17:06:29 +02:00
Ryan Liptak 5e3fa0e94f Add rename to std.fs API
- Moves fs.rename functions to fs.renameAbsolute to match other functions outside of fs.Dir
- Adds fs.Dir.rename that takes two paths relative to the given Dir
- Adds fs.rename that takes two separate Dir's that the given paths are relative to (for renaming across directories without having to make the second path relative to a single directory)
- Fixes FileNotFound error return in std.os.windows.MoveFileExW
- Returns error.RenameAcrossMountPoints from renameatW
  + Matches the RenameAcrossMountPoints error return in renameatWasi/renameatZ
2020-09-17 17:22:26 -04:00
LemonBoy 3c8e1bc25b std: Fix for 32bit systems 2020-09-04 12:48:36 +02:00