Unison Help
- Unison Kernel
- Pthreads
- pthread_create()
- pthread_exit()
- pthread_self()
- pthread_equal()
- pthread_join()
- pthread_detach()
- pthread_setschedparam()
- pthread_getschedparam()
- pthread_attr_init()
- pthread_attr_destroy()
- pthread_attr_setstackaddr()
- pthread_attr_getstackaddr()
- pthread_attr_setstacksize()
- pthread_attr_getstacksize()
- pthread_attr_setschedparam()
- pthread_attr_getschedparam()
- pthread_attr_setdetachstate()
- pthread_attr_getdetachstate()
- pthread_stackinfo()
- pthread_setprio()
- pthread_getprio()
- sched_get_priority_max()
- sched_get_priority_min()
- sched_yield()
- Pthread Cancellation
- Mutex
- Semaphores
- Message Queues
- Conditional Variables
- Barriers
- Timers
- Clocks
- Memory Allocation
- Rendezvous
- Interrupts
- Directory Services
- Miscellaneous
- Pthreads
- Unison I/O Library
- Unison STDIO Library
- STDIO Library Calls
- clearerr()
- dprintf()
- fclose()
- fdopen()
- feof()
- ferror()
- fileno()
- fflush()
- fgetc()
- fgetpos()
- fgets()
- fopen()
- fprintf()
- fputc()
- fputs()
- fread()
- freopen()
- fscanf()
- fseek()
- fseeko()
- fsetpos()
- ftell()
- ftello()
- fwrite()
- getc()
- getc_unlocked()
- getchar()
- getchar_unlocked()
- getdelim()
- getline()
- gets()
- get_stderr_ptr()
- get_stdin_ptr()
- get_stdout_ptr()
- noperprintf()
- perprintf()
- perror()
- posix_compat()
- printf()
- putc()
- putc_unlocked()
- putchar()
- putchar_unlocked()
- puts()
- remove()
- rewind()
- scanf()
- setbuf()
- setvbuf()
- snprintf()
- sprintf()
- sscanf()
- stderr_init()
- stderr_close()
- stdin_init()
- stdin_close()
- stdout_init()
- stdout_close()
- vdprintf()
- vscanf()
- vsscanf()
- vfscanf()
- vprintf()
- vsnprintf()
- vsprintf()
- vfprintf()
- ungetc()
- Do-nothing Stubs
- STDIO Library Calls
- Unison LIBC Library
- Unison I/O Servers
- Graphics, Camera, Video, Audio
- Network Protocols
- TCP and UDP Server - tcpd
- DHCP Client Service - dhcp client
- DHCP Server - dhcpd
- Telnet Server - telnetd
- Tiny FTP Server - tftpd
- Point to Point - pppd
- Network Translation - NAT with PAT
- Firewall
- Tiny HTTP Server - thttpd
- Tiny HTTP Server with TLS
- POP3 Server
- Simple Mail Transfer Protocol Services (SMTP)
- Bootp Protocol
- File Transfer Protocol Server (FTP)
- File Transfer Client Services
- RPC / XDR
- DNS Client
- HTTP/HTTPS Client
- REST Client
- AutoIP Service - autoip client
- mDNS server - mdnsd
- SNTP Client
- SNMP Agent - Snmpd server
- SSL/TLS library
- SSH server
- IP security
- Power Control
- Serial I/O
- System Services
- Universal Serial Bus (USB)
- Wireless
- Remedy Tools for Unison
3.1.38.posix_compat() #
NAME
posix_compat – assign stdin/stdout/stderr device names
end_posix_compat – release stdin/stdout/stderr device names
SYNOPSIS
#include <stdio.h>
- int posix_compat(char *cwd, char *stdinServerName, char *stdoutServerName, char *stderrServerName);
- int end_posix_compat(void);
DESCRIPTION
The user defined function, posix_compat(), is used to encapsulate any specific setup which an application requires from startup.
Typically, a standard LINUX/UNIX application may look for certain devices to be present when it is evoked. Additionally, many STDIO runtime functions (such as printf(), getc(), etc.) will only operate if their expected device exists.
In most cases, this requirement can be satisfied by defining the following three devices through parameters for posix_compat():
- cwd
- the current working directory (usually a R/W disk device).
- stdin
- the standard input device (usually a TTY console).
- stdout
- the standard output device (usually a TTY console).
- stderr
- the standard error device (usually a TTY console).
Of course, other environment and run-time definitions can also be placed in this encapsulation, as needed. By transferring all server setup into this call along with the assignment of stdin, stdout and stderr, the packaging of Unison applications becomes much closer to a multi-threaded LINUX program. This approach is highly recommended because it allows application developers from the Linux world to separate the application from the underlying device drivers and the initialization process.
If required, the paired user defined function, end_posix_compat(), can be used to reverse (or undo) the actions performed by posix_compat(). Typically, this would involve closing the standard devices and freeing user assignments. Generally, servers which have been started by posix_compat() should not be canceled; however, in some cases it may be necessary.
For a typical usage, see the example below.
RETURN VALUES
User defined
EXAMPLE
int posix_compat(char *cwd, char *stdinServerName, char *stdoutServerName, char *stderrServerName) { pthread_t pid; pthread_attr_t attr; struct sched_param myNewPriority; struct set_tty *set_tty; pthread_attr_init(&attr); myNewPriority.sched_priority = 5; pthread_attr_setschedparam(&attr, &myNewPriority); pthread_attr_setstacksize(&attr,1100); if(pthread_create(&pid, &attr, &tty_shell, 0)!=0) { xprintf("Can't create tty_shell = %d\n", errno); return 0; } if(dir_register("/dev/ttyS", pid, TYPE_SERVER)==0) { xprintf("Can't register '/dev/ttyS' = %d\n", errno); return 0; } stdin_init (stdinServerName); perprintf(stdout_init (stdoutServerName)); if (stderrServerName != NULL) stderr_init (stderrServerName); return 1; } int end_posix_compat() { stderr_close(); stdout_close(); stdin_close(); return 1; } THREAD Main(void *arg) { ... posix_compat("", "/dev/ttyS0", "/dev/ttyS0", "/dev/ttyS0"); // Print to stdout printf("Start tty with posix_compat\n"); ... // Read from stdin gets(buf); ... // Print to stderr perror("error"); ... }