libc.obj:

- Added pipe example;
 - Fixed Makefile.

git-svn-id: svn://kolibrios.org@9725 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2022-02-22 22:16:42 +00:00
parent e07e44044e
commit a89837dd81
4 changed files with 96 additions and 3 deletions

View File

@ -1435,6 +1435,46 @@ int _ksys_file_rename(const char *name, const char *new_name)
return _ksys_work_files(&k); return _ksys_work_files(&k);
} }
/*============= Function 77 - implements the POSIX subsystem. =============*/
static inline
int _ksys_posix_read(int pipefd, void* buff, int n)
{
int count;
asm_inline(
"int $0x40"
:"=a"(count)
:"a"(77), "b"(10),"c"(pipefd), "d"(buff), "S"(n)
:"memory"
);
return count;
}
static inline
int _ksys_posix_write(int pipefd, void* buff, int n)
{
int count;
asm_inline(
"int $0x40"
:"=a"(count)
:"a"(77), "b"(11),"c"(pipefd), "d"(buff), "S"(n)
:"memory"
);
return count;
}
static inline
int _ksys_posix_pipe2(int pipefd[2], int flags)
{
int err;
asm_inline(
"int $0x40"
:"=a"(err)
:"a"(77), "b"(13),"c"(pipefd), "d"(flags)
:"memory"
);
return err;
}
/* ######### Old names of functions and structures. Do not use again! ##########*/ /* ######### Old names of functions and structures. Do not use again! ##########*/

View File

@ -2,7 +2,7 @@ KTCC = kos32-tcc
FASM = fasm FASM = fasm
KPACK = kpack KPACK = kpack
CFLAGS = -I../include -B../../kx -I../../../../../../contrib/sdk/sources/SDL-1.2.2_newlib/include CFLAGS = -I../include -B../../bin -I../../../../../../contrib/sdk/sources/SDL-1.2.2_newlib/include
LIBS = -lbox_lib -lshell -lSDL -lsound -lnetwork -lrasterworks -limg -ldialog -lmsgbox LIBS = -lbox_lib -lshell -lSDL -lsound -lnetwork -lrasterworks -limg -ldialog -lmsgbox
BIN = stdio_test.kex \ BIN = stdio_test.kex \
@ -24,6 +24,7 @@ BIN = stdio_test.kex \
sdltest.kex \ sdltest.kex \
shell_test.kex \ shell_test.kex \
libc_test.kex \ libc_test.kex \
pipe.kex \
defgen.kex defgen.kex
all: $(BIN) all: $(BIN)

View File

@ -19,7 +19,8 @@ cp clayer/logo.png /tmp0/1/tcc_samples/logo.png
../tcc thread_work.c -o /tmp0/1/tcc_samples/thread_work ../tcc thread_work.c -o /tmp0/1/tcc_samples/thread_work
../tcc -I../include/SDL sdltest.c -o /tmp0/1/tcc_samples/sdltest -lSDL -lsound ../tcc -I../include/SDL sdltest.c -o /tmp0/1/tcc_samples/sdltest -lSDL -lsound
../tcc shell_test.c -o /tmp0/1/tcc_samples/shell_test -lshell ../tcc shell_test.c -o /tmp0/1/tcc_samples/shell_test -lshell
../tcc libc_test.c -o /tmp0/1/tcc_samples/libc_test ../tcc libc_test.c -o /tmp0/1/tcc_samples/libc_test
../tcc defgen.c -o /tmp0/1/tcc_samples/defgen ../tcc defgen.c -o /tmp0/1/tcc_samples/defgen
../tcc pipe.c -o /tmp0/1/tcc_samples/pipe
"/sys/File managers/Eolite" /tmp0/1/tcc_samples "/sys/File managers/Eolite" /tmp0/1/tcc_samples
exit exit

View File

@ -0,0 +1,51 @@
/*
* This is an example program for sending a message through a "pipe".
* Created by turbocat (Maxim Logaev) 2022.
*/
#include <sys/ksys.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#define TH_STACK_SIZE 1024
#define MESSAGE_SIZE 12
ksys_colors_table_t sys_colors;
int pipefd[2];
char *send_message = "HELLO PIPE!";
void tmain() {
char recv_message[MESSAGE_SIZE];
_ksys_posix_read(pipefd[0], recv_message, MESSAGE_SIZE);
printf("RECV: %s\n", recv_message);
assert(!strcmp(recv_message, send_message));
puts("Successful pipe test");
exit(0);
}
void create_thread(void){
unsigned tid; // New thread ID
void *th_stack = malloc(TH_STACK_SIZE); // Allocate memory for thread stack
if (!th_stack) {
puts("Memory allocation error for thread!");
return;
}
tid = _ksys_create_thread(tmain, th_stack+TH_STACK_SIZE); // Create new thread with entry "main"
if (tid == -1) {
puts("Unable to create a new thread!");
return;
}
printf("New thread created (TID=%u)\n", tid);
}
void main() {
if (_ksys_posix_pipe2(pipefd, 0)) {
puts("Pipe creation error!");
return;
}
printf("SEND: %s\n", send_message);
_ksys_posix_write(pipefd[1], send_message, MESSAGE_SIZE);
create_thread();
}