ridiculousfish
4b4bf541d1
Migrate more fd-concerned functions from wutil into fds
...
Functions like wopen_cloexec have a new home in fds.cpp. This is in
preparation for reworking how internal fds avoid conflict with user fds.
2021-02-05 17:58:08 -08:00
Fabian Homborg
2e55e34544
Reformat
2020-11-22 14:39:48 +01:00
Fabian Homborg
568f9031aa
builtin realpath: Add --no-symlinks option
...
Taken from GNU realpath, this one makes realpath not resolve symlinks.
It still makes paths absolute and handles duplicate and trailing
slashes.
(useful in fish_add_path)
2020-09-12 19:26:04 +02:00
Johannes Altmanninger
de9874e4de
Remove some useless casts
...
I think the warnings from -Wuseless-cast are mostly platform-specific but
I hope these are correct.
2020-09-08 22:44:03 +02:00
Johannes Altmanninger
fbaa5d193d
Declare functions in headers or use internal linkage (static)
...
Found with gcc's -Wmissing-declarations which gives warnings like
../src/tinyexpr.cpp:61:5: warning: no previous declaration for ‘int get_arity(int)’ [-Wmissing-declarations]
61 | int get_arity(const int type) {
The same warnings show up for builtin functions like builtin_bg because they
currently don't include their own headers. I left that.
Also reformat the touched files.
2020-09-08 22:44:03 +02:00
ridiculousfish
c1abb474c2
Remove some dead code and enable a test
2020-08-09 15:05:16 -07:00
ridiculousfish
2809d637db
Introduce wwrite_to_fd
...
wwrite_to_fd() is a function which writes a wide string to a file
descriptor without performing any heap allocations.
2020-07-29 19:38:45 -07:00
ridiculousfish
c9b42c6f1f
Stop #include-ing wcstringutil.h in flog.h
...
This is a header dependency that we can break.
2020-07-29 17:04:18 -07:00
ridiculousfish
db086fc5d4
Eliminate wcs2str
...
Use std::string variants everywhere instead
2020-07-29 16:37:39 -07:00
ridiculousfish
462313f930
Remove ASSERT_IS_NOT_FORKED_CHILD from open_cloexec
...
This was tripping initialization order checks from ASAN, and is
otherwise not a very useful check here.
2020-06-07 19:58:52 -07:00
Rosen Penev
0668513138
Change C casts to C++ ones
...
Some were kept for compatibility.
Found with -Wold-style-cast
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-05-01 13:30:56 -07:00
David Adam
8d43439640
wutil: add SMB2 file type to fd_check_is_remote
...
The manual page for statfs(2) only lists SMB_SUPER_MAGIC and
CIFS_MAGIC_NUMBER, but it turns out there's a third type of CIFS/SMB
mount, represented by SMB2_MAGIC_NUMBER.
Haunting me from #6609 .
2020-04-29 23:34:13 +08:00
Rosen Penev
473a5250ae
[clang-tidy] change several member functions to const
...
Found with readability-make-member-function-const
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Rosen Penev
312b575424
[clang-tidy] numeric literals to uppercase
...
Found with hicpp-uppercase-literal-suffix
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Fabian Homborg
65883e0e40
Restyle
...
Mostly line breaks, one instance of tabs!
For some reason clang-format insists on two spaces before a same-line comment?
(I continue to be unimpressed with super-strict line length limits,
but I continue to believe in automatic styling, so it is what it is)
[ci skip]
2020-02-17 14:14:05 +01:00
Fabian Homborg
399a71645e
Fix build on 32-bit systems
...
This was a weird case of the integer converseys.
Fixes #6609 .
2020-02-15 10:13:56 +01:00
ridiculousfish
28a8d0dbf7
Continued adoption of autoclose_fd_t and exec_close
2020-01-29 14:16:16 -08:00
ridiculousfish
fc4557c784
Eliminate wopen()
...
It was large and mostly unnecessary. Prefer wopen() followed by
fdopen().
2020-01-28 10:43:37 -08:00
ridiculousfish
1bbfb7044b
Remove wopen
...
It was unused
2020-01-28 10:26:31 -08:00
ridiculousfish
f27958ef4d
Clean up the open_cloexec interface
...
Remove the ability to make it non-cloexec - nobody was using it.
2020-01-28 10:25:49 -08:00
Rosen Penev
f2e7def667
[clang-tidy] Remove const from strings
...
Found with readability-const-return-type
2019-12-26 21:25:12 -08:00
ridiculousfish
9be77d1f9c
Correctly handle "self fd redirections"
...
This adds a test for the obscure case where an fd is redirected to
itself. This is tricky because the dup2 will not clear the CLO_EXEC bit.
So do it manually; also posix_spawn can't be used in this case.
2019-12-13 16:51:49 -08:00
Rosen Penev
6f4a9d527c
[clang-tidy] Use C++ using instead of C typedef
...
Found with modernize-use-using
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
7d1cc992e5
[clang-tidy] Simplify boolean expressions
...
Found with readability-simplify-boolean-expr
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
1055ff321c
[clang-tidy] Replace NULL with nullptr
...
Found with modernize-use-nullptr
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:23:03 -08:00
Rosen Penev
0dfa7421f3
[clang-tidy] Convert C casts to C++ ones
...
Found with google-readability-casting
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:17:49 -08:00
ridiculousfish
82eca4bc86
Run clang-format on all files
...
The main change here is to reorder headers.
2019-10-13 15:50:48 -07:00
ridiculousfish
42138f00c6
Remove wchdir()
...
It's unused, and will soon be dangerous as the process-wide cwd will
lose meaning.
2019-06-10 09:37:08 -07:00
ridiculousfish
6ce85aebc6
Switch file_io_t to store a wcstring
...
We no longer use file_io_t after fork(). We don't need to use a malloc'd
string any more. Use a wcstring.
2019-06-09 17:43:25 -07:00
Fabian Homborg
bc19647be2
wutil: Give narrow versions of a few functions
...
Note that this isn't technically *w*util, but the differences between
the functions are basically just whether they do the wcs2string
themselves or not.
2019-06-01 09:34:47 +02:00
Fabian Homborg
d73ee4d54b
More using FLOGF when formatting is needed
...
sed-patched, every time a "%" is used in a call to `FLOG`, we use
`FLOGF` instead.
2019-05-30 11:54:09 +02:00
Fabian Homborg
6617c4d79e
Use C++11 value-initialization instead of { 0 }
...
Removes a warning in GCC.
2019-05-29 20:50:35 +02:00
ridiculousfish
835c6ffa67
clang-format all files
2019-05-27 19:47:13 -07:00
ridiculousfish
ea9d1ad82f
Convert debug(0) calls to FLOG
2019-05-27 17:31:17 -07:00
Fabian Homborg
c2970f9618
Reformat all files
...
This runs build_tools/style.fish, which runs clang-format on C++, fish_indent on fish and (new) black on python.
If anything is wrong with the formatting, we should fix the tools, but automated formatting is worth it.
2019-05-05 12:09:25 +02:00
ridiculousfish
36998eee55
Make more miscellaneous globals thread safe
2019-05-04 20:58:35 -07:00
ridiculousfish
2c7dc98337
Revert "fcntl a little less"
...
This reverts commits:
e5362a4ae5
.
dd9a26715d
.
These commits were incorrect because they stomped other flags, such as
O_NONBLOCK.
2019-04-13 12:27:05 -07:00
Aaron Gyes
e5362a4ae5
wutil.cpp: fixup: don't involve the uninitialized parameter
2019-04-08 16:02:00 -07:00
Aaron Gyes
dd9a26715d
fcntl a little less
...
Setting O_CLOEXEC on closed file descriptors and getting E_BADF
should be faster than actually checking if an fd is open first.
2019-04-08 11:23:00 -07:00
Aaron Gyes
d837eee09d
remove some wcstring -> wchar_t* -> wcstring conversions
...
Mostly related to usage _(L"foo"), keeping in mind the _
macro does a wcstring().c_str() already.
And a smattering of other trivial micro-optimizations certain
to not help tangibly.
2019-03-14 15:21:08 -07:00
Aaron Gyes
aaacdb89b6
Switches over to cstring from string.h.
2019-03-12 15:09:36 -07:00
Aaron Gyes
d5ac239f68
This commit changes wchar.h includes to cwchar, and uses std::
...
for everything it provides.
2019-03-12 15:09:36 -07:00
Fabian Homborg
12d7c7feb6
Switch to readdir from readdir_r
...
It's deprecated in glibc, and does not work properly on Solaris.
Fixes #5458 .
2019-01-03 11:19:45 +01:00
Fabian Homborg
9b980f5e6e
Use fstatvfs if ST_LOCAL is available
...
Allows us to sometimes use mmap on NetBSD (proper capitalization is
important).
2018-12-31 14:24:24 +01:00
Fabian Homborg
3e03625113
Don't try to use fstatfs on netbsd
...
I can find a man page for it, but it doesn't seem to work.
2018-12-31 14:24:22 +01:00
Fabian Homborg
7367e545f2
Revert "wrealpath: Fail for file/something"
...
Apparently macOS realpath is broken.
This reverts commit ca1c499069
.
2018-11-19 09:12:26 +01:00
ridiculousfish
a8ce7bad7b
Always pass in the working directory in path_get_cdpath
...
If the user is in a directory which has been unlinked, it is possible
for the path .. to not exist, relative to the working directory.
Always pass in the working directory (potentially virtual) to
path_get_cdpath; this ensures we check absolute paths and are immune
from issues if the working directory has been unlinked.
Also introduce a new function path_normalize_for_cd which normalizes the
"join point" of a path and a working directory. This allows us to 'cd' out of
a non-existent directory, but not cd into such a directory.
Fixes #5341
2018-11-18 14:36:42 -08:00
Aaron Gyes
4221d6c3e6
Realpath styling tweaks.
...
Add braces I forgot, improve comments, make line spacing more
consistent around if blocks.
2018-11-18 12:29:35 -08:00
Fabian Homborg
442eb028c1
wrealpath: Simplify
...
- Reuse the buffer
- Don't duplicate the code for no "/"
2018-11-18 20:30:26 +01:00
Fabian Homborg
ca1c499069
wrealpath: Fail for file/something
...
This incorrectly allowed "file/something" if file existed (as a file), because it
checked "afile".
Fixes #5352 .
2018-11-18 20:30:21 +01:00