Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 9718 → Rev 9725

/programs/develop/ktcc/trunk/libc.obj/include/sys/ksys.h
1435,7 → 1435,47
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! ##########*/
 
#define _ksys_get_event _ksys_wait_event
/programs/develop/ktcc/trunk/libc.obj/samples/Makefile
2,7 → 2,7
FASM = fasm
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
 
BIN = stdio_test.kex \
24,6 → 24,7
sdltest.kex \
shell_test.kex \
libc_test.kex \
pipe.kex \
defgen.kex
all: $(BIN)
/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh
21,5 → 21,6
../tcc shell_test.c -o /tmp0/1/tcc_samples/shell_test -lshell
../tcc libc_test.c -o /tmp0/1/tcc_samples/libc_test
../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
exit
/programs/develop/ktcc/trunk/libc.obj/samples/pipe.c
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();
}