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
6 changes: 3 additions & 3 deletions library/c.lib_rev.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define REVISION 4
#define SUBREVISION 1

#define DATE "23.12.2024"
#define DATE "01.01.2025"
#define VERS "clib4.library 1.4.1"
#define VSTRING "clib4.library 1.4.1 (23.12.2024)\r\n"
#define VERSTAG "\0$VER: clib4.library 1.4.1-5d728de (23.12.2024)"
#define VSTRING "clib4.library 1.4.1 (01.01.2025)\r\n"
#define VERSTAG "\0$VER: clib4.library 1.4.1-5d728de (01.01.2025)"
5 changes: 5 additions & 0 deletions library/socket/hook_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ __socket_hook_entry(struct _clib4 *__clib4, struct fd *fd, struct file_action_me
break;
case file_action_examine:
SHOWMSG("file_action_examine");

/* Create an empty examineData struct */
struct ExamineData *examineData = __malloc_r(__clib4, sizeof(struct ExamineData));
fam->fam_FileInfo = examineData;

fib = fam->fam_FileInfo;
memset(fib, 0, sizeof(*fib));
fib->Type = ST_SOCKET;
Expand Down
16 changes: 9 additions & 7 deletions library/stat/fstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ fstat(int file_descriptor, struct stat *buffer) {

__convert_file_info_to_stat(fam.fam_FileSystem, fam.fam_FileInfo, buffer);

if (fam.fam_FileInfo->Type != ST_CONSOLE) {
/* Close ExamineObjectTag object created when fd->fd_Action is executed */
FreeDosObject(DOS_EXAMINEDATA, fam.fam_FileInfo);
}
else {
/* If ExamineObjectTag was failed we have to free the dummy ExamineData structure created */
__free_r(__clib4, fam.fam_FileInfo);
if(fam.fam_FileInfo->Type != ST_NIL) {
if (fam.fam_FileInfo->Type != ST_CONSOLE) {
/* Close ExamineObjectTag object created when fd->fd_Action is executed */
FreeDosObject(DOS_EXAMINEDATA, fam.fam_FileInfo);
}
else {
/* If ExamineObjectTag was failed we have to free the dummy ExamineData structure created */
__free_r(__clib4, fam.fam_FileInfo);
}
}

result = OK;
Expand Down
1 change: 1 addition & 0 deletions library/stdio/fdhookentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ int64_t __fd_hook_entry(struct _clib4 *__clib4, struct fd *fd, struct file_actio

/* Special treatment for "NIL:", for which we make some stuff up. */
if (fh->fh_MsgPort == NULL) {

/* Make up some stuff for this stream. */
memset(fam->fam_FileInfo, 0, sizeof(*fam->fam_FileInfo));

Expand Down
74 changes: 30 additions & 44 deletions library/stdio/popen.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ popen(const char *command, const char *type) {
char *command_copy = NULL;
BPTR input = BZERO;
BPTR output = BZERO;
// char pipe_file_name[40];
BPTR error = BZERO;
char pipe_file_name[40];
FILE *result = NULL;
LONG status;
// unsigned long task_address;
// time_t now = 0;
unsigned long task_address;
time_t now = 0;
int i;

struct _clib4 *__clib4 = __CLIB4;
Expand Down Expand Up @@ -180,11 +181,6 @@ popen(const char *command, const char *type) {
command = command_copy;
}

// Let's use out super cool pipe implementation instead :
int p[2];
pipe(p);

#if 0
/* Build a (hopefully) unique name for the pipe stream to open. We
construct it from the current process address, converted into
an octal number, followed by the current time (in seconds),
Expand All @@ -211,56 +207,50 @@ popen(const char *command, const char *type) {
pipe_file_name[i] = '\0';

SHOWSTRING(pipe_file_name);
#endif

/* Now open the input and output streams for the program to launch. */
if (type[0] == 'r') {
/* Read mode: we want to read the output of the program; the program
should read from "NIL:". */
input = Open("NIL:", MODE_NEWFILE);
input = Open("NIL:", MODE_OLDFILE);
if (input != BZERO) {
// output = Open(pipe_file_name, MODE_NEWFILE);
int err = __get_default_file(p[1], &output);
if (err) {
__set_errno(EBADF);
goto out;
}
output = DupFileHandle(output);
output = Open(pipe_file_name, MODE_NEWFILE);
}
} else {
/* Write mode: we want to send data to the program; the program
should write to "NIL:". */
// input = Open(pipe_file_name, MODE_NEWFILE);
int err = __get_default_file(p[0], &input);
if (err) {
__set_errno(EBADF);
goto out;
}
input = DupFileHandle(input);
input = Open(pipe_file_name, MODE_NEWFILE);
if (input != BZERO)
output = Open("NIL:", MODE_NEWFILE);
output = Open("NIL:", MODE_OLDFILE);
}
// error = DupFileHandle(ErrorOutput()); //
error = Open("NIL:", MODE_OLDFILE);

/* Check if both I/O streams could be opened. */
if (input == BZERO || output == BZERO) {
if (input == BZERO || output == BZERO || error == BZERO) {
SHOWMSG("couldn't open the streams");

__set_errno_r(__clib4, __translate_io_error_to_errno(IoErr()));
goto out;
}

// printf("[popen :] Launching [%s]\n", command);

D(("Launching [%s]", command));
/* Now try to launch the program. */
status = SystemTags((STRPTR) command,
SYS_Input, input,
SYS_Output, output,
SYS_Asynch, TRUE,
SYS_UserShell, TRUE,
NP_Name, command,
NP_EntryCode, spawnedProcessEnter,
NP_EntryData, getgid(),
NP_ExitCode, spawnedProcessExit,
NP_Child, TRUE,
SYS_Input, input,
SYS_Output, output,
SYS_Error, error, // <-- We have to block this with NIL:
NP_CloseError, TRUE,
SYS_Asynch, TRUE,
SYS_UserShell, TRUE,
NP_StackSize, 2024*1024,
NP_Name, command,
NP_EntryCode, spawnedProcessEnter,
NP_EntryData, getgid(),
NP_ExitCode, spawnedProcessExit,
NP_Child, TRUE,
TAG_END);

uint32 ret;
Expand All @@ -283,18 +273,11 @@ popen(const char *command, const char *type) {
}
/* OK, the program is running. Once it terminates, it will automatically
shut down the streams we opened for it. */
input = output = BZERO;
input = output = error = BZERO;

/* Now try to open the pipe we will use to exchange data with the program. */
// result = fopen(pipe_file_name, type);
result = fopen(pipe_file_name, type);

if (type[0] == 'r') {
result = fdopen(p[0], "r");
close(p[1]);
} else {
result = fdopen(p[1], "w");
close(p[0]);
}
if(result) addSpawnedChildrenPipeHandle(ret, result); //pid, pipe

out:
Expand All @@ -308,6 +291,9 @@ popen(const char *command, const char *type) {
if (output != BZERO)
Close(output);

if (error != BZERO)
Close(error);

RETURN(result);
return (result);
}
4 changes: 4 additions & 0 deletions library/termios/console_fdhookentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ __termios_console_hook(struct _clib4 *__clib4, struct fd *fd, struct file_action
goto out;
}

/* Create an empty examineData struct */
struct ExamineData *examineData = __malloc_r(__clib4, sizeof(struct ExamineData));
fam->fam_FileInfo = examineData;

/* Make up some stuff for this stream. */
memset(fam->fam_FileInfo, 0, sizeof(*fam->fam_FileInfo));

Expand Down
7 changes: 6 additions & 1 deletion library/unistd/spawnv.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ spawnv(int mode, const char *file, const char **argv) {
BPTR in = DupFileHandle(Input());
BPTR out = DupFileHandle(Output());
BPTR err = DupFileHandle(ErrorOutput());
D(("Launching [%s]", finalpath));
D(("Launching [%s]", command));
ret = SystemTags(command,
SYS_Input, in,
SYS_Output, out,
Expand Down Expand Up @@ -206,6 +206,11 @@ spawnv(int mode, const char *file, const char **argv) {
*/
if (mode == P_NOWAIT) {
ret = IoErr(); // This is our ProcessID;
} else {
if (in)
Close(in);
if (out)
Close(out);
}
}
return ret;
Expand Down
2 changes: 2 additions & 0 deletions library/unistd/spawnvpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ spawnvpe(
SYS_Asynch, TRUE,
NP_Child, TRUE,

NP_StackSize, 2024*1024,

// This is taken care of by the command shell :
// progdirLock ? NP_ProgramDir : TAG_SKIP, progdirLock,

Expand Down
3 changes: 3 additions & 0 deletions library/unistd/translateu2a.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@

int
__translate_unix_to_amiga_path_name(char const **name_ptr, struct name_translation_info *nti) {

// printf("[path translate :] name_ptr [%s]\n", *name_ptr);

int result = ERROR;
char *name;

Expand Down
3 changes: 0 additions & 3 deletions test_programs/popen/child.c

This file was deleted.

25 changes: 0 additions & 25 deletions test_programs/popen/popen_test.c

This file was deleted.

33 changes: 33 additions & 0 deletions test_programs/popen/popen_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <string>
#include <iostream>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv) {
if(argc < 2) return 0;

enableUnixPaths();

std::string result;

FILE *proc;
proc = popen(argv[1], "r");
// proc = popen("/qt6-amiga/libexec/rcc", "r"); // -list -name textures textures.qrc", "r");
// proc = popen("/SDK/gcc/bin/gcc -mcrt=clib4 -Wl,--verbose xc++ -o NIL:", "r");

if (!proc) {
printf("Unable to open piped process.\n");
return 0;
}

char buff[1024];
while(fgets(buff, sizeof(buff), proc) != NULL)
result += buff;

int ec = pclose(proc);

std::cout << "output: [" << result << "]" << std::endl;

printf("return code : %d\n", ec);

return 0;
}