Skip to content

Commit 3f3ec1a

Browse files
author
Jan Philipp Hafer
committed
move over 1 minimal used function to CI test things.
1 parent 998460f commit 3f3ec1a

File tree

3 files changed

+60
-42
lines changed

3 files changed

+60
-42
lines changed

lib/std/fs/file.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,14 @@ pub const File = struct {
393393
return Stat.fromSystem(st);
394394
}
395395

396-
pub const ChmodError = std.os.FChmodError;
396+
pub const ChmodError = std.os.posix.FChmodError;
397397

398398
/// Changes the mode of the file.
399399
/// The process must have the correct privileges in order to do this
400400
/// successfully, or must have the effective user ID matching the owner
401401
/// of the file.
402402
pub fn chmod(self: File, new_mode: Mode) ChmodError!void {
403-
try os.fchmod(self.handle, new_mode);
403+
try os.posix.fchmod(self.handle, new_mode);
404404
}
405405

406406
pub const ChownError = std.os.FChownError;

lib/std/os.zig

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub const uefi = @import("os/uefi.zig");
4040
pub const wasi = @import("os/wasi.zig");
4141
pub const windows = @import("os/windows.zig");
4242

43+
pub const posix = @import("os/posix.zig"); // posix
4344
pub const posix_spawn = @import("os/posix_spawn.zig"); // posix
4445
pub const ptrace = @import("os/ptrace.zig"); // posix
4546
pub const dragonfly = std.c;
@@ -62,6 +63,8 @@ test {
6263
if (builtin.os.tag == .uefi) {
6364
_ = uefi;
6465
}
66+
67+
_ = posix;
6568
}
6669

6770
/// Applications can override the `system` API layer in their root source file.
@@ -291,46 +294,6 @@ pub fn close(fd: fd_t) void {
291294
}
292295
}
293296

294-
pub const FChmodError = error{
295-
AccessDenied,
296-
InputOutput,
297-
SymLinkLoop,
298-
FileNotFound,
299-
SystemResources,
300-
ReadOnlyFileSystem,
301-
} || UnexpectedError;
302-
303-
/// Changes the mode of the file referred to by the file descriptor.
304-
/// The process must have the correct privileges in order to do this
305-
/// successfully, or must have the effective user ID matching the owner
306-
/// of the file.
307-
pub fn fchmod(fd: fd_t, mode: mode_t) FChmodError!void {
308-
if (builtin.os.tag == .windows or builtin.os.tag == .wasi)
309-
@compileError("Unsupported OS");
310-
311-
while (true) {
312-
const res = system.fchmod(fd, mode);
313-
314-
switch (system.getErrno(res)) {
315-
.SUCCESS => return,
316-
.INTR => continue,
317-
.BADF => unreachable, // Can be reached if the fd refers to a non-iterable directory.
318-
319-
.FAULT => unreachable,
320-
.INVAL => unreachable,
321-
.ACCES => return error.AccessDenied,
322-
.IO => return error.InputOutput,
323-
.LOOP => return error.SymLinkLoop,
324-
.NOENT => return error.FileNotFound,
325-
.NOMEM => return error.SystemResources,
326-
.NOTDIR => return error.FileNotFound,
327-
.PERM => return error.AccessDenied,
328-
.ROFS => return error.ReadOnlyFileSystem,
329-
else => |err| return unexpectedErrno(err),
330-
}
331-
}
332-
}
333-
334297
pub const FChownError = error{
335298
AccessDenied,
336299
InputOutput,

lib/std/os/posix.zig

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//! This file contains posix abstractions and wrappers around
2+
//! OS-specific APIs for conforming platforms, whether libc is or is not linked.
3+
//! APIs defined here can not have comparable semantics on Windows.
4+
5+
const std = @import("std");
6+
const builtin = @import("builtin");
7+
const os = std.os;
8+
9+
// Constants
10+
const UnexpectedError = os.UnexpectedError;
11+
const fd_t = os.fd_t;
12+
const mode_t = os.mode_t;
13+
const system = os.system;
14+
// Functions
15+
const unexpectedErrno = os.unexpectedErrno;
16+
17+
pub const FChmodError = error{
18+
AccessDenied,
19+
InputOutput,
20+
SymLinkLoop,
21+
FileNotFound,
22+
SystemResources,
23+
ReadOnlyFileSystem,
24+
} || UnexpectedError;
25+
26+
/// Changes the mode of the file referred to by the file descriptor.
27+
/// The process must have the correct privileges in order to do this
28+
/// successfully, or must have the effective user ID matching the owner
29+
/// of the file.
30+
pub fn fchmod(fd: fd_t, mode: mode_t) FChmodError!void {
31+
if (builtin.os.tag == .windows or builtin.os.tag == .wasi)
32+
@compileError("Unsupported OS");
33+
34+
while (true) {
35+
const res = system.fchmod(fd, mode);
36+
37+
switch (system.getErrno(res)) {
38+
.SUCCESS => return,
39+
.INTR => continue,
40+
.BADF => unreachable, // Can be reached if the fd refers to a non-iterable directory.
41+
42+
.FAULT => unreachable,
43+
.INVAL => unreachable,
44+
.ACCES => return error.AccessDenied,
45+
.IO => return error.InputOutput,
46+
.LOOP => return error.SymLinkLoop,
47+
.NOENT => return error.FileNotFound,
48+
.NOMEM => return error.SystemResources,
49+
.NOTDIR => return error.FileNotFound,
50+
.PERM => return error.AccessDenied,
51+
.ROFS => return error.ReadOnlyFileSystem,
52+
else => |err| return unexpectedErrno(err),
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)