Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ListTalk/ListTalk.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <ListTalk/classes/List.h>
#include <ListTalk/classes/ImmutableList.h>
#include <ListTalk/classes/Pair.h>
#include <ListTalk/classes/Pathname.h>
#include <ListTalk/classes/Package.h>
#include <ListTalk/classes/Symbol.h>
#include <ListTalk/classes/SourceLocation.h>
Expand Down
67 changes: 67 additions & 0 deletions ListTalk/classes/Pathname.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026 Ales Hakl
*/
#ifndef H__ListTalk__Pathname__
#define H__ListTalk__Pathname__

#include <ListTalk/classes/String.h>
#include <ListTalk/macros/decl_macros.h>

LT__BEGIN_DECLS

typedef struct LT_Pathname_s LT_Pathname;
typedef struct LT_RelativePathname_s LT_RelativePathname;
typedef struct LT_AbsolutePathname_s LT_AbsolutePathname;

extern LT_Class LT_Pathname_class;
extern LT_Class LT_Pathname_class_class;
LT_DECLARE_CLASS(LT_RelativePathname);
LT_DECLARE_CLASS(LT_AbsolutePathname);
LT_DECLARE_CLASS(LT_PathnameStat);

static inline int LT_Pathname_p(LT_Value value){
return LT_Value_is_instance_of(value, LT_STATIC_CLASS(LT_Pathname));
}

static inline LT_Pathname* LT_Pathname_from_value(LT_Value value){
if (!LT_Pathname_p(value)){
LT_type_error(value, &LT_Pathname_class);
}
return (LT_Pathname*)LT_VALUE_POINTER_VALUE(value);
}

LT_Pathname* LT_Pathname_new(char* pathname);
LT_Pathname* LT_Pathname_from_string(LT_String* string);
LT_RelativePathname* LT_RelativePathname_new(char* pathname);
LT_RelativePathname* LT_RelativePathname_from_string(LT_String* string);
LT_AbsolutePathname* LT_AbsolutePathname_new(char* pathname);
LT_AbsolutePathname* LT_AbsolutePathname_from_string(LT_String* string);
LT_Pathname* LT_Pathname_append(LT_Pathname* left, LT_Pathname* right);
LT_Pathname* LT_Pathname_parent(LT_Pathname* pathname);
LT_Pathname* LT_AbsolutePathname_rooted_at(
LT_AbsolutePathname* pathname,
LT_Pathname* root
);
LT_String* LT_Pathname_as_string(LT_Pathname* pathname);
const char* LT_Pathname_value_cstr(LT_Pathname* pathname);
int LT_Pathname_absolute_p(LT_Pathname* pathname);
Comment on lines +46 to +48
int LT_Pathname_relative_p(LT_Pathname* pathname);
int LT_Pathname_exists_p(LT_Pathname* pathname);
int LT_Pathname_directory_p(LT_Pathname* pathname);
int LT_Pathname_regular_file_p(LT_Pathname* pathname);
int LT_Pathname_symbolic_link_p(LT_Pathname* pathname);
int LT_Pathname_fifo_p(LT_Pathname* pathname);
int LT_Pathname_socket_p(LT_Pathname* pathname);
int LT_Pathname_character_device_p(LT_Pathname* pathname);
int LT_Pathname_block_device_p(LT_Pathname* pathname);
int LT_Pathname_readable_p(LT_Pathname* pathname);
int LT_Pathname_writable_p(LT_Pathname* pathname);
int LT_Pathname_executable_p(LT_Pathname* pathname);
LT_PathnameStat* LT_Pathname_stat(LT_Pathname* pathname);
LT_PathnameStat* LT_Pathname_lstat(LT_Pathname* pathname);
const char* LT_Pathname_like_value_cstr(LT_Value value);
LT_String* LT_Pathname_like_as_string(LT_Value value);
Comment on lines +62 to +64

LT__END_DECLS
#endif
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ vm_lib = library(
'src/classes/Float.c',
'src/classes/List.c',
'src/classes/String.c',
'src/classes/Pathname.c',
'src/classes/Vector.c',
'src/classes/BitVector.c',
'src/classes/ByteVector.c',
Expand Down
15 changes: 8 additions & 7 deletions src/classes/ByteVector.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <ListTalk/classes/Number.h>
#include <ListTalk/classes/Primitive.h>
#include <ListTalk/classes/String.h>
#include <ListTalk/classes/Pathname.h>
#include <ListTalk/classes/Boolean.h>
#include <ListTalk/classes/List.h>
#include <ListTalk/utils.h>
Expand Down Expand Up @@ -305,17 +306,17 @@ LT_DEFINE_PRIMITIVE(
){
LT_Value cursor = arguments;
LT_Value self;
LT_String* filename;
LT_Value filename;
uint8_t* bytes;
size_t length;
(void)tail_call_unwind_marker;

LT_OBJECT_ARG(cursor, self);
LT_GENERIC_ARG(cursor, filename, LT_String*, LT_String_from_value);
LT_OBJECT_ARG(cursor, filename);
LT_ARG_END(cursor);
(void)self;

bytes = read_file_bytes(LT_String_value_cstr(filename), &length);
bytes = read_file_bytes(LT_Pathname_like_value_cstr(filename), &length);
return (LT_Value)(uintptr_t)LT_ByteVector_new(bytes, length);
}

Expand Down Expand Up @@ -367,19 +368,19 @@ LT_DEFINE_PRIMITIVE(
){
LT_Value cursor = arguments;
LT_ByteVector* bytevector;
LT_String* filename;
LT_Value filename;
(void)tail_call_unwind_marker;

LT_GENERIC_ARG(cursor, bytevector, LT_ByteVector*, LT_ByteVector_from_value);
LT_GENERIC_ARG(cursor, filename, LT_String*, LT_String_from_value);
LT_OBJECT_ARG(cursor, filename);
LT_ARG_END(cursor);

LT_write_file_bytes_atomically(
LT_String_value_cstr(filename),
LT_Pathname_like_value_cstr(filename),
LT_ByteVector_bytes(bytevector),
LT_ByteVector_length(bytevector)
);
return (LT_Value)(uintptr_t)filename;
return filename;
}

LT_DEFINE_PRIMITIVE(
Expand Down
Loading