fputws_unlocked - Linux
Overview
fputws_unlocked writes a wide character to a stream, without the requirement of a mutex lock. It is primarily used for efficient character output operations in multithreaded applications.
Syntax
int fputws_unlocked(const wchar_t *wcs, FILE *stream);
Options/Flags
None
Examples
Simple Use:
#include <stdio.h>
#include <wchar.h>
int main() {
FILE *fp = fopen("output.txt", "w");
fputws_unlocked(L"Wide Character String", fp);
fclose(fp);
return 0;
}
Writing a Wide Character String to a File Pointer:
wchar_t wcstring[] = L"Wide Character String in a Variable";
FILE *fp = fopen("output.txt", "wb");
fputws_unlocked(wcstring, fp);
fclose(fp);
Common Issues
- Incorrect Stream: Ensure that the provided stream is valid and open for writing.
- NULL Characters: wcs should be a null-terminated wide character string. Otherwise, the behavior is undefined.
Integration
Multithreaded Character Output:
pthread_mutex_lock(&stream_lock);
fputws_unlocked(wcstring, stream);
pthread_mutex_unlock(&stream_lock);
Writing Wide Characters to a Pipe:
$ echo "Wide Character String" | iconv -f UTF-8 -t UTF-16 | fputws_unlocked -
Related Commands
- fprintf: Formatted wide character output to a stream
- fwprintf: Formatted wide character output to a FILE pointer
- fputwc: Write a wide character to a stream