Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
107cfed
Wrong Printf version requirement printing
afxgroup Jan 28, 2025
5b66b34
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Apr 15, 2025
fec31be
Merge pull request #271 from AmigaLabs/master
walkero-gr Apr 28, 2025
905bc88
Merge branch 'master' into development
walkero-gr Apr 28, 2025
f28a4c4
Improved memalign (#272)
afxgroup Jun 7, 2025
35539a9
Pthreads fixes (#273)
afxgroup Jun 10, 2025
c7de956
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Jun 11, 2025
7d6500a
Roundeven functions (#274)
afxgroup Jun 15, 2025
183789d
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Jun 18, 2025
dd0350c
Profile fixes (#278)
afxgroup Jun 22, 2025
3cc20ed
Small change on profile reverted (#279)
afxgroup Jun 23, 2025
71a4f1a
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Jun 23, 2025
7c22f41
Canonicalize file name (#281)
afxgroup Jun 28, 2025
f63710d
Fixed a crash when debug was enabled (#282)
afxgroup Jun 29, 2025
e0470de
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Jun 30, 2025
fec61cd
Ctype (#283)
afxgroup Jul 3, 2025
9b02227
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Jul 4, 2025
254e7ba
Fix memory alignment in SIMPLE and BLOCK_FAST memory allocators (wmem).
elfpipe Jul 11, 2025
49e9c76
Merge branch 'development' of https://github.com/AmigaLabs/clib4 into…
elfpipe Jul 11, 2025
a842ec2
Fix alignment issues with wmem allocator (BLOCK).
elfpipe Jul 23, 2025
a940a01
Delete unnecessary files.
elfpipe Jul 23, 2025
fb358b0
Allocator alignment (#284)
elfpipe Jul 23, 2025
a2b9be9
Fix problem with jumbo blocks (wmem - BLOCK).
elfpipe Jul 24, 2025
a814c5f
Merge branch 'development' into allocator_alignment
elfpipe Jul 26, 2025
c13d3db
Merge pull request #285 from AmigaLabs/allocator_alignment
elfpipe Jul 26, 2025
b6928d6
Remove #endif.
elfpipe Jul 26, 2025
0ee9533
Merge pull request #286 from AmigaLabs/allocator_alignment
elfpipe Jul 26, 2025
f8d315d
Fixed pthread lib (#287)
afxgroup Jul 29, 2025
8a6f8e2
Tidy up memory allocation code. Fix singular problem with BLOCK. Sugg…
elfpipe Aug 1, 2025
f057d34
Speedup I/O a little bit (#289)
afxgroup Aug 1, 2025
d7bd69f
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Aug 1, 2025
dd9fea4
Fixed a problem on Input/Output/Error streams (#290)
afxgroup Aug 5, 2025
64d3630
Preliminary fix for the workbench startup message issue. (#291)
elfpipe Aug 6, 2025
83adeb9
This is another fix for the BLOCK allocator. (#292)
elfpipe Aug 7, 2025
5b3cae8
Various speed up improvements (#293)
afxgroup Aug 14, 2025
67b1257
Replaced Semaphores with Mutexes in pthread library (#294)
afxgroup Aug 16, 2025
e023cca
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Aug 20, 2025
67f9dd9
mkdir() was causing a DSI when directory had a '/' at the end (#308)
afxgroup Aug 21, 2025
7ccefe3
File io fixes (#309)
afxgroup Aug 23, 2025
7267674
use clib4 if version is higher than previous one (#310)
afxgroup Aug 24, 2025
3164ed9
Version check was wrong (#311)
afxgroup Aug 24, 2025
773989d
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Aug 25, 2025
3835366
Fixed DSI on setvbuf (#312)
afxgroup Aug 25, 2025
a9f53cb
Merge branch 'development' of github.com:AmigaLabs/clib4 into develop…
afxgroup Aug 26, 2025
424b185
Fixed development merge conflicts
afxgroup Aug 26, 2025
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
2 changes: 1 addition & 1 deletion library/crtbegin.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ clib4_start(char *args, const int32 arglen, struct Library *sysbase) {
iclib4 = (struct Clib4IFace *) OpenLibraryInterface(iexec, "clib4.library", 1);
if (iclib4 != NULL) {
const struct Library *clib4base = ((struct Interface *) iclib4)->Data.LibBase;
if (clib4base->lib_Version >= VERSION && clib4base->lib_Revision >= REVISION) {
if (clib4base->lib_Version > VERSION || (clib4base->lib_Version == VERSION && clib4base->lib_Revision >= REVISION)) {
IClib4 = iclib4;

rc = iclib4->library_start(args, arglen, main, __CTOR_LIST__, __DTOR_LIST__, sms);
Expand Down
13 changes: 9 additions & 4 deletions library/fcntl/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
int
open(const char *path_name, int open_flag, ... /* mode_t mode */) {
struct _clib4 *__clib4 = __CLIB4;
return __open_r(__clib4, path_name, open_flag);
va_list ap;
va_start(ap, open_flag);
return __open_r(__clib4, path_name, open_flag, va_arg(ap, int));
va_end(ap);
}

int
Expand Down Expand Up @@ -265,10 +268,12 @@ __open_r(struct _clib4 *__clib4, const char *path_name, int open_flag, ... /* mo

fd = __clib4->__fd[fd_slot_number];

if (is_directory || FLAG_IS_SET(open_flag, O_PATH))
if (is_directory || FLAG_IS_SET(open_flag, O_PATH)) {
__initialize_fd(fd, __fd_hook_entry, dir_lock, 0, fd_lock); // TODO - Create a new dir hook
else
}
else {
__initialize_fd(fd, __fd_hook_entry, handle, 0, fd_lock);
}

fd->fd_Aux = (char *) path_name;

Expand Down Expand Up @@ -384,7 +389,7 @@ __open_r(struct _clib4 *__clib4, const char *path_name, int open_flag, ... /* mo
if (lock != BZERO)
UnLock(lock);

if (dir_lock != BZERO)
if (!is_directory && dir_lock != BZERO)
UnLock(dir_lock);

__stdio_unlock(__clib4);
Expand Down
1 change: 1 addition & 0 deletions library/libc_init_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ reent_init(struct _clib4 *__clib4, const BOOL fallback) {
.isTZSet = 0,
.__IDebug = NULL,
.resolv_conf = NULL,
.__file_lock_semaphore_name = "Advisory File Locking"
};

if (!__clib4->__random_lock || !__clib4->__pipe_semaphore) {
Expand Down
7 changes: 4 additions & 3 deletions library/stat/mkdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ int mkdir(const char *path_name, mode_t mode) {
}
}

char *path_to_create = (char *) path_name;
char path_to_create[PATH_MAX] = {0};
strncpy(path_to_create, path_name, PATH_MAX - 1);

/* This check avoid that for some mistakes a directory contain more than one : char inside the name
* This could help to avoid problems on SFS file system that allow (by mistake) the creation of dirs
* like DriveName:Dir/DriveName:Dir
*/

int counter = 0;
for (int i = 0; path_to_create[i]; i++) {
size_t len = strlen(path_to_create);
for (size_t i = 0; i < len; i++) {
if (path_to_create[i] == ':') {
counter++;
}
Expand All @@ -61,7 +63,6 @@ int mkdir(const char *path_name, mode_t mode) {
goto out;
}

size_t len = strlen(path_to_create);
if (path_to_create[len - 1] == '/') {
path_to_create[len - 1] = '\0'; // Remove '/' if present
}
Expand Down
5 changes: 4 additions & 1 deletion library/stdio/fclose.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ fclose(FILE *stream) {
/* Get rid of any custom file buffer allocated. */
if (file->iob_CustomBuffer != NULL) {
SHOWMSG("Delete allocated buffer");
ItemPoolFree(__clib4->_iob_pool, file->iob_CustomBuffer);
if (file->iob_isVBuffer)
FreeVec(file->iob_CustomBuffer);
else
ItemPoolFree(__clib4->_iob_pool, file->iob_CustomBuffer);
file->iob_CustomBuffer = NULL;
}

Expand Down
8 changes: 4 additions & 4 deletions library/stdio/fdhookentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,10 @@ int64_t __fd_hook_entry(struct _clib4 *__clib4, struct fd *fd, struct file_actio
// TODO - Check this on OS4 with NIL:
fam->fam_FileInfo->Type = ST_NIL;
} else {
BPTR lock_type = FLAG_IS_SET(fd->fd_Flags, FDF_IS_DIRECTORY) || FLAG_IS_SET(fd->fd_Flags, FDF_PATH_ONLY)
? EX_LockInput
: EX_FileHandleInput;
fam->fam_FileInfo = ExamineObjectTags(lock_type, file, TAG_DONE);
if (FLAG_IS_SET(fd->fd_Flags, FDF_IS_DIRECTORY) || FLAG_IS_SET(fd->fd_Flags, FDF_PATH_ONLY))
fam->fam_FileInfo = ExamineObjectTags(EX_LockInput, file, TAG_DONE);
else
fam->fam_FileInfo = ExamineObjectTags(EX_FileHandleInput, file, TAG_DONE);
if (fam->fam_FileInfo == NULL) {
LONG error;

Expand Down
1 change: 1 addition & 0 deletions library/stdio/initializeiob.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ __initialize_iob(
memset(iob, 0, sizeof(*iob));

iob->iob_CustomBuffer = custom_buffer;
iob->iob_isVBuffer = FALSE;
iob->iob_Buffer = (UBYTE *)buffer;
iob->iob_BufferSize = buffer_size;
iob->iob_Descriptor = file_descriptor;
Expand Down
12 changes: 8 additions & 4 deletions library/stdio/record_locking.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,11 @@ __handle_record_locking(struct _clib4 *__clib4, int cmd, struct flock *l, struct
_off64_t seek_position;
_off64_t current_position;
int result = ERROR;
_off64_t original_len;
_off64_t original_len = 0;
LONG error = OK;
_off64_t start = 0;
_off64_t len = 0;
_off64_t stop;
_off64_t stop = 0;

ENTER();

Expand All @@ -591,7 +591,7 @@ __handle_record_locking(struct _clib4 *__clib4, int cmd, struct flock *l, struct
/* Remember to unlock any records before closing the file. */
fd->fd_Cleanup = cleanup_locked_records;

if ((cmd == F_SETLK || cmd == F_SETLKW) && (l->l_type != F_UNLCK)) {
if ((cmd == F_SETLK || cmd == F_SETLKW) && (l->l_type == F_WRLCK || l->l_type == F_RDLCK)) {
SHOWMSG("this is a lock request");

error = create_file_lock_node(__clib4, fd, &fln);
Expand All @@ -605,7 +605,11 @@ __handle_record_locking(struct _clib4 *__clib4, int cmd, struct flock *l, struct
SHOWMSG("could not create region node");
goto out;
}
} else {
}
else if (l->l_type == F_UNLCK) {
SHOWMSG("this is an unlock request");
}
else {
SHOWMSG("this is not a lock request");
goto out;
}
Expand Down
28 changes: 18 additions & 10 deletions library/stdio/setvbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ setvbuf(FILE *stream, char *buf, int bufmode, size_t size) {
buf = NULL;
}

/* If a certain buffer size is requested but no buffer was provided,
allocate some memory for it. */
/* If a certain buffer size is requested but no buffer was provided, allocate some memory for it. */
if (bufmode != IOBF_BUFFER_MODE_NONE) {
/* If a certain buffer size is requested but no buffer was provided,
allocate some memory for it. */
if (size > 0 && buf == NULL) {
/* Allocate a little more memory than necessary. */
new_buffer = ItemPoolAlloc(__clib4->_iob_pool);
/* Allocate a little more memory than necessary and align it to a cache line boundary. */
new_buffer = AllocVecTags(size, AVT_Type, MEMF_SHARED, AVT_ClearWithValue, 0, AVT_Alignment, __clib4->__cache_line_size, TAG_DONE);
if (new_buffer == NULL) {
__set_errno_r(__clib4, ENOBUFS);
goto out;
Expand All @@ -98,7 +97,14 @@ setvbuf(FILE *stream, char *buf, int bufmode, size_t size) {
/* Get rid of any buffer specially allocated for this stream. */
if (file->iob_CustomBuffer != NULL) {
SHOWMSG("Delete allocated buffer");
ItemPoolFree(__clib4->_iob_pool, file->iob_CustomBuffer);
if (file->iob_isVBuffer) {
FreeVec(file->iob_CustomBuffer);
file->iob_isVBuffer = FALSE;
}
else {
ItemPoolFree(__clib4->_iob_pool, file->iob_CustomBuffer);
}

file->iob_CustomBuffer = NULL;
}

Expand All @@ -111,11 +117,9 @@ setvbuf(FILE *stream, char *buf, int bufmode, size_t size) {
if (buf != NULL) {
new_buffer = (char *) buf;
} else {
file->iob_isVBuffer = TRUE;
/* Remember this, so we can release it later. */
file->iob_CustomBuffer = new_buffer;

/* Align the buffer start address to a cache line boundary. */
new_buffer = (char *) ((ULONG)(new_buffer + (__clib4->__cache_line_size - 1)) & ~(__clib4->__cache_line_size - 1));
}
}

Expand All @@ -137,8 +141,12 @@ setvbuf(FILE *stream, char *buf, int bufmode, size_t size) {

__funlockfile_r(__clib4, stream);

if (new_buffer != NULL)
ItemPoolFree(__clib4->_iob_pool, new_buffer);
if (new_buffer != NULL) {
if (file->iob_isVBuffer)
FreeVec(file->iob_CustomBuffer);
else
ItemPoolFree(__clib4->_iob_pool, file->iob_CustomBuffer);
}

RETURN(result);
return result;
Expand Down
1 change: 1 addition & 0 deletions library/stdio/stdio_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ typedef struct iob {
UBYTE iob_SingleByte; /* Fall-back buffer for 'unbuffered' files */
APTR iob_Lock; /* For thread locking */
struct Task * iob_TaskLock; /* Task who owns lock */
BOOL iob_isVBuffer; /* TRUE if iob_CustomBuffer is set from setvbuf */
} __iob64;


Expand Down
2 changes: 1 addition & 1 deletion library/wmem/wmem_allocator_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ wmem_block_split_used_chunk(wmem_block_allocator_t *allocator,
bool last;

#ifdef MEMORY_DEBUG
D(("[split_used :] chunk : 0x%lx\n", chunk));
D(("[split_used :] data : 0x%lx\n", data));
#endif

aligned_size = size + ((uintptr_t)data - (uintptr_t)WMEM_DATA_TO_CHUNK(data));
Expand Down
2 changes: 1 addition & 1 deletion os4depot.readme
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: clib4 library
version: VERSION_TAG
author: Andrea Palmatè
submitter: Andrea Palmatè
email: os4test@amigasoft.net
email: andrea@amigasoft.net
url: https://github.com/AmigaLabs/clib4
category: development/library/misc
replaces: development/library/misc/clib4.lha
Expand Down
45 changes: 45 additions & 0 deletions test_programs/io/open_dir.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>

int main(void) {
const char *dir_path = "T:"; // Use the current directory
int fd;
struct stat sb;

// Open the directory
printf("Attempting to open directory: '%s'\n", dir_path);
fd = open(dir_path, O_RDONLY);
if (fd == -1) {
perror("open");
exit(EXIT_FAILURE);
}
printf("Directory opened successfully with file descriptor: %d\n", fd);

// Get file status using fstat() on the file descriptor
if (fstat(fd, &sb) == -1) {
perror("fstat");
close(fd);
exit(EXIT_FAILURE);
}
printf("fstat() called successfully on the file descriptor.\n");

// Print some information from the stat buffer
printf("File type: ");
switch (sb.st_mode & S_IFMT) {
case S_IFDIR: printf("directory\n"); break;
case S_IFREG: printf("regular file\n"); break;
case S_IFLNK: printf("symbolic link\n"); break;
default: printf("unknown?\n"); break;
}
printf("Number of hard links: %ld\n", (long) sb.st_nlink);
printf("File size: %lld bytes\n", (long long) sb.st_size);

// Close the file descriptor
close(fd);
printf("File descriptor closed.\n");

return 0;
}
28 changes: 28 additions & 0 deletions test_programs/io/setvbuf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>

#define BUF_SIZE 1024

int main(void) {
char buffer[BUF_SIZE];

printf("Initial output.\n");
printf("This line is in the default buffer, but will be flushed at the end.\n");

// Use setvbuf to assign a new, fully buffered buffer to stdout.
if (setvbuf(stdout, buffer, _IOFBF, BUF_SIZE) != 0) {
perror("setvbuf failed");
return 1;
}

printf("This text is now being written to the new custom buffer.\n");
printf("You will not see this until the buffer is full, or the program ends.\n");

// We can prove the custom buffer is used by forcing a flush.
// Uncomment the next line to see the output immediately.
fflush(stdout);

printf("Final line before exit.\n");

return 0;
}