Skip to content

Commit

Permalink
Update some places in the std lib where octal literals are better
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer committed Aug 8, 2022
1 parent 603e302 commit aeb4ff2
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion media/test-project/os-test.spice
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ f<int> main() {
}*/

f<int> main() {
printf("Test: %d\n", 0xfff);
printf("Test: %d\n", 0o0000777);
}
34 changes: 17 additions & 17 deletions std/io/dir_linux.spice
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
//import "std/os/os" as os;

// File permission modes
public const int MODE_ALL_RWX = 511; // Decimal for octal: 0000777
public const int MODE_ALL_RW = 438; // Decimal for octal: 0000666
public const int MODE_ALL_R = 292; // Decimal for octal: 0000444
public const int MODE_ALL_RWX = 0o0000777;
public const int MODE_ALL_RW = 0o0000666;
public const int MODE_ALL_R = 0o0000444;

public const int MODE_OWNER_RWX = 448; // Decimal for octal: 0000700
public const int MODE_OWNER_R = 256; // Decimal for octal: 0000400
public const int MODE_OWNER_W = 128; // Decimal for octal: 0000200
public const int MODE_OWNER_X = 64; // Decimal for octal: 0000100
public const int MODE_OWNER_RWX = 0o0000700;
public const int MODE_OWNER_R = 0o0000400;
public const int MODE_OWNER_W = 0o0000200;
public const int MODE_OWNER_X = 0o0000100;

public const int MODE_GROUP_RWX = 56; // Decimal for octal: 0000070
public const int MODE_GROUP_R = 32; // Decimal for octal: 0000040
public const int MODE_GROUP_W = 16; // Decimal for octal: 0000020
public const int MODE_GROUP_X = 8; // Decimal for octal: 0000010
public const int MODE_GROUP_RWX = 0o0000070;
public const int MODE_GROUP_R = 0o0000040;
public const int MODE_GROUP_W = 0o0000020;
public const int MODE_GROUP_X = 0o0000010;

public const int MODE_OTHER_RWX = 7; // Decimal for octal: 0000007
public const int MODE_OTHER_R = 4; // Decimal for octal: 0000004
public const int MODE_OTHER_W = 2; // Decimal for octal: 0000002
public const int MODE_OTHER_X = 1; // Decimal for octal: 0000001
public const int MODE_OTHER_RWX = 0o0000007;
public const int MODE_OTHER_R = 0o0000004;
public const int MODE_OTHER_W = 0o0000002;
public const int MODE_OTHER_X = 0o0000001;

const int F_OK = 0; // File existence
const int X_OK = 1; // Can execute
const int W_OK = 2; // Can write
const int R_OK = 4; // Can read

const int IF_MT = 61440; // Decimal for octal: 0170000
const int IF_DIR = 16384; // Decimal for octal: 0040000
const int IF_MT = 0o0170000;
const int IF_DIR = 0o0040000;

type FileStat struct { // Total size: 46 bytes
unsigned long st_dev // ID of the device containing file
Expand Down
36 changes: 18 additions & 18 deletions std/io/dir_windows.spice
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
//import "std/os/os" as os;

// File permission modes
public const int MODE_ALL_RWX = 511; // Decimal for octal: 0000777
public const int MODE_ALL_RW = 438; // Decimal for octal: 0000666
public const int MODE_ALL_R = 292; // Decimal for octal: 0000444

public const int MODE_OWNER_RWX = 448; // Decimal for octal: 0000700
public const int MODE_OWNER_R = 256; // Decimal for octal: 0000400
public const int MODE_OWNER_W = 128; // Decimal for octal: 0000200
public const int MODE_OWNER_X = 64; // Decimal for octal: 0000100

public const int MODE_GROUP_RWX = 56; // Decimal for octal: 0000070
public const int MODE_GROUP_R = 32; // Decimal for octal: 0000040
public const int MODE_GROUP_W = 16; // Decimal for octal: 0000020
public const int MODE_GROUP_X = 8; // Decimal for octal: 0000010

public const int MODE_OTHER_RWX = 7; // Decimal for octal: 0000007
public const int MODE_OTHER_R = 4; // Decimal for octal: 0000004
public const int MODE_OTHER_W = 2; // Decimal for octal: 0000002
public const int MODE_OTHER_X = 1; // Decimal for octal: 0000001
public const int MODE_ALL_RWX = 0o0000777;
public const int MODE_ALL_RW = 0o0000666;
public const int MODE_ALL_R = 0o0000444;

public const int MODE_OWNER_RWX = 0o0000700;
public const int MODE_OWNER_R = 0o0000400;
public const int MODE_OWNER_W = 0o0000200;
public const int MODE_OWNER_X = 0o0000100;

public const int MODE_GROUP_RWX = 0o0000070;
public const int MODE_GROUP_R = 0o0000040;
public const int MODE_GROUP_W = 0o0000020;
public const int MODE_GROUP_X = 0o0000010;

public const int MODE_OTHER_RWX = 0o0000007;
public const int MODE_OTHER_R = 0o0000004;
public const int MODE_OTHER_W = 0o0000002;
public const int MODE_OTHER_X = 0o0000001;

const int F_OK = 0; // File existence
const int X_OK = 1; // Can execute
Expand Down
28 changes: 14 additions & 14 deletions std/io/file_linux.spice
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// File open modes
public const string MODE_READ = "r";
public const string MODE_WRITE = "w";
public const string MODE_APPEND = "a";
public const string MODE_READ_WRITE = "r+";
public const string MODE_READ_WRITE_OVERWRITE = "w+";
public const string MODE_READ_WRITE_APPEND = "a+";
public const string MODE_READ = "r";
public const string MODE_WRITE = "w";
public const string MODE_APPEND = "a";
public const string MODE_READ_WRITE = "r+";
public const string MODE_READ_WRITE_OVERWRITE = "w+";
public const string MODE_READ_WRITE_APPEND = "a+";

const int MODE_CREATE = 64; // Decimal for octal: 100
const int MODE_RDWR = 2; // Decimal for octal: 2
const int MODE_CREATE = 0o100;
const int MODE_RDWR = 0o002;

const int F_OK = 0; // File existence
const int X_OK = 1; // Can execute
Expand Down Expand Up @@ -50,7 +50,7 @@ public f<int> createFile(string path) {

/**
* Opens a (new) file at the specified path with the specified mode.
*
*
* There are predefined constants for the mode available:
* MODE_READ, MODE_WRITE, MODE_APPEND,
* MODE_READ_WRITE, MODE_READ_WRITE_OVERWRITE, MODE_READ_WRITE_APPEND
Expand Down Expand Up @@ -84,7 +84,7 @@ public f<int> File.readChar() {

/**
* Writes a single character to the file.
*
*
* @return Result code of the write operation: 0 = successful, -1 = failed
*/
public f<int> File.writeChar(char value) {
Expand Down Expand Up @@ -169,7 +169,7 @@ public f<long> getFileSize(string path) {

/**
* Checks if a file exists. The function also returns true if the specified path points to a directory.
*
*
* @return Existing / not existing
*/
public f<bool> fileExists(string path) {
Expand All @@ -178,7 +178,7 @@ public f<bool> fileExists(string path) {

/**
* Checks if the read permissions to a file are given.
*
*
* @return Readable / not readable
*/
public f<bool> fileReadable(string path) {
Expand All @@ -187,7 +187,7 @@ public f<bool> fileReadable(string path) {

/**
* Checks if the write permissions to a file are given.
*
*
* @return Writable / not writable
*/
public f<bool> fileWritable(string path) {
Expand All @@ -196,7 +196,7 @@ public f<bool> fileWritable(string path) {

/**
* Checks if the execute permissions to a file are given.
*
*
* @return Executable / not executable
*/
public f<bool> fileExecutable(string path) {
Expand Down
28 changes: 14 additions & 14 deletions std/io/file_windows.spice
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// File open modes
public const string MODE_READ = "r";
public const string MODE_WRITE = "w";
public const string MODE_APPEND = "a";
public const string MODE_READ_WRITE = "r+";
public const string MODE_READ_WRITE_OVERWRITE = "w+";
public const string MODE_READ_WRITE_APPEND = "a+";
public const string MODE_READ = "r";
public const string MODE_WRITE = "w";
public const string MODE_APPEND = "a";
public const string MODE_READ_WRITE = "r+";
public const string MODE_READ_WRITE_OVERWRITE = "w+";
public const string MODE_READ_WRITE_APPEND = "a+";

const int MODE_CREATE = 64; // Decimal for octal: 100
const int MODE_RDWR = 2; // Decimal for octal: 2
const int MODE_CREATE = 0x100;
const int MODE_RDWR = 0x002;

const int F_OK = 0; // File existence
const int X_OK = 1; // Can execute
Expand Down Expand Up @@ -50,7 +50,7 @@ public f<int> createFile(string path) {

/**
* Opens a (new) file at the specified path with the specified mode.
*
*
* There are predefined constants for the mode available:
* MODE_READ, MODE_WRITE, MODE_APPEND,
* MODE_READ_WRITE, MODE_READ_WRITE_OVERWRITE, MODE_READ_WRITE_APPEND
Expand Down Expand Up @@ -84,7 +84,7 @@ public f<int> File.readChar() {

/**
* Writes a single character to the file.
*
*
* @return Result code of the write operation: 0 = successful, -1 = failed
*/
public f<int> File.writeChar(char value) {
Expand Down Expand Up @@ -169,7 +169,7 @@ public f<long> getFileSize(string path) {

/**
* Checks if a file exists. The function also returns true if the specified path points to a directory.
*
*
* @return Existing / not existing
*/
public f<bool> fileExists(string path) {
Expand All @@ -178,7 +178,7 @@ public f<bool> fileExists(string path) {

/**
* Checks if the read permissions to a file are given.
*
*
* @return Readable / not readable
*/
public f<bool> fileReadable(string path) {
Expand All @@ -187,7 +187,7 @@ public f<bool> fileReadable(string path) {

/**
* Checks if the write permissions to a file are given.
*
*
* @return Writable / not writable
*/
public f<bool> fileWritable(string path) {
Expand All @@ -196,7 +196,7 @@ public f<bool> fileWritable(string path) {

/**
* Checks if the execute permissions to a file are given.
*
*
* @return Executable / not executable
*/
public f<bool> fileExecutable(string path) {
Expand Down

0 comments on commit aeb4ff2

Please sign in to comment.