refactor: remove conditional compilation layers

This commit is contained in:
2026-08-12 17:27:42 +09:00
parent 91931196e2
commit 0d06ba43cd
4 changed files with 19 additions and 47 deletions

39
ipc.c
View File

@@ -7,10 +7,6 @@
#include <sys/un.h> #include <sys/un.h>
#include "ipc.h" #include "ipc.h"
#if !defined(MSG_NOSIGNAL) && !defined(SO_NOSIGPIPE)
#error "ipcsend requires MSG_NOSIGNAL or SO_NOSIGPIPE"
#endif
static void static void
putlen(unsigned char p[Ipclensz], size_t n) putlen(unsigned char p[Ipclensz], size_t n)
{ {
@@ -68,8 +64,8 @@ ipcconnect(void)
} }
void void
ipcpackreq(unsigned char req[Ipcreqsz], int want, unsigned int mod, ipcpackreq(unsigned char req[Ipcreqsz], int want, uint32_t mod,
unsigned int key) uint32_t key)
{ {
req[0] = want ? Ipcreqwant : 0; req[0] = want ? Ipcreqwant : 0;
req[1] = mod; req[1] = mod;
@@ -87,15 +83,15 @@ ipcpackreset(unsigned char req[Ipcreqsz], int want)
} }
void void
ipcunpackreq(const unsigned char req[Ipcreqsz], int *want, unsigned int *mod, ipcunpackreq(const unsigned char req[Ipcreqsz], int *want, uint32_t *mod,
unsigned int *key) uint32_t *key)
{ {
*want = (req[0] & Ipcreqwant) != 0; *want = (req[0] & Ipcreqwant) != 0;
*mod = req[1] & Mmask; *mod = req[1] & Mmask;
*key = (unsigned int)req[2] | *key = (uint32_t)req[2] |
((unsigned int)req[3] << 8) | ((uint32_t)req[3] << 8) |
((unsigned int)req[4] << 16) | ((uint32_t)req[4] << 16) |
((unsigned int)req[5] << 24); ((uint32_t)req[5] << 24);
} }
int int
@@ -156,27 +152,10 @@ ipcsend(int fd, const void *buf, size_t n)
{ {
const unsigned char *p; const unsigned char *p;
ssize_t r; ssize_t r;
int flags;
#if !defined(MSG_NOSIGNAL) && defined(SO_NOSIGPIPE)
int one, sr;
#endif
p = buf; p = buf;
#ifdef MSG_NOSIGNAL
flags = MSG_NOSIGNAL;
#else
flags = 0;
#ifdef SO_NOSIGPIPE
one = 1;
do
sr = setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof one);
while(sr < 0 && errno == EINTR);
if(sr < 0)
return -1;
#endif
#endif
while(n > 0){ while(n > 0){
r = send(fd, p, n, flags); r = send(fd, p, n, MSG_NOSIGNAL);
if(r < 0 && errno == EINTR) if(r < 0 && errno == EINTR)
continue; continue;
if(r <= 0) if(r <= 0)

10
ipc.h
View File

@@ -1,7 +1,5 @@
#ifndef STRANS_IPC_H
#define STRANS_IPC_H
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
/* /*
* Request: [flags, modifiers, key byte 0, ..., key byte 3]. * Request: [flags, modifiers, key byte 0, ..., key byte 3].
@@ -51,9 +49,9 @@ struct Ipcresp
size_t npreedit; size_t npreedit;
}; };
void ipcpackreq(unsigned char[Ipcreqsz], int, unsigned int, unsigned int); void ipcpackreq(unsigned char[Ipcreqsz], int, uint32_t, uint32_t);
void ipcpackreset(unsigned char[Ipcreqsz], int); void ipcpackreset(unsigned char[Ipcreqsz], int);
void ipcunpackreq(const unsigned char[Ipcreqsz], int*, unsigned int*, unsigned int*); void ipcunpackreq(const unsigned char[Ipcreqsz], int*, uint32_t*, uint32_t*);
int ipcreqreset(const unsigned char[Ipcreqsz]); int ipcreqreset(const unsigned char[Ipcreqsz]);
int ipcpackresp(unsigned char*, size_t, int, const char*, size_t, const char*, size_t, int); int ipcpackresp(unsigned char*, size_t, int, const char*, size_t, const char*, size_t, int);
int ipcreadn(int, void*, size_t); int ipcreadn(int, void*, size_t);
@@ -61,5 +59,3 @@ int ipcsend(int, const void*, size_t);
int ipcreadresp(int, int, char*, size_t, char*, size_t, Ipcresp*); int ipcreadresp(int, int, char*, size_t, char*, size_t, Ipcresp*);
int ipcpath(char*, size_t); int ipcpath(char*, size_t);
int ipcconnect(void); int ipcconnect(void);
#endif

View File

@@ -1,6 +1,11 @@
#define STRANS_TEST_ENGINE
#include "../strans.c" #include "../strans.c"
#include "test.h" #include "../cutest/cutest.h"
extern Lang testvi;
Str mkstr(char*);
int checkstr(struct ct*, char*, char*, Str*);
Str shownpre(Im*);
static int typekeys(struct ct*, char*, Str*); static int typekeys(struct ct*, char*, Str*);

View File

@@ -1,12 +1,6 @@
#ifndef STRANS_TEST_H
#define STRANS_TEST_H
#include "../cutest/cutest.h" #include "../cutest/cutest.h"
#ifndef STRANS_TEST_ENGINE
#include "../dat.h" #include "../dat.h"
#include "../fn.h" #include "../fn.h"
#endif
extern Lang testvi; extern Lang testvi;
@@ -72,5 +66,3 @@ void ipc_response_empty_and_preedit(struct ct*);
void ipc_response_max_and_drain(struct ct*); void ipc_response_max_and_drain(struct ct*);
void ipc_response_fragmented_and_truncated(struct ct*); void ipc_response_fragmented_and_truncated(struct ct*);
void ipc_broken_peer_send(struct ct*); void ipc_broken_peer_send(struct ct*);
#endif