Files
kolibrios/programs/develop/ktcc/libc.obj/samples/pipe.c
T
ace-dentandBurer a4f3f3545a develop/ktcc: Post-SVN tidy (#425)
- Move source code from `trunk` into root directory.
- Update build files and ASM include paths. Add SPDX license header where appropriate.
- These changes also update the CI build files in `.gitea/workflows/`.
- Note: Line endings standardised from `CRLF` > `LF`, so best to view diffs with whitespace changes hidden.

(Work towards [#75](KolibriOS/kolibrios#75), point 3)

---------

Co-authored-by: Burer <burer@kolibrios.org>
Reviewed-on: KolibriOS/kolibrios#425
Reviewed-by: Mikhail Frolov <mixa.frolov2003@gmail.com>
Reviewed-by: Burer <burer@kolibrios.org>
Co-authored-by: Andrew <dent.ace@gmail.com>
Co-committed-by: Andrew <dent.ace@gmail.com>
2026-04-19 16:41:37 +00:00

55 lines
1.3 KiB
C

/*
* This is an example program for sending a message through a "pipe".
* Created by turbocat (Maxim Logaev) 2022.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ksys.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();
}