commit 58cd29ae1d8bc4c8cdde76e511cea65b59b05115
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2026-05-27T15:07:32Z |
| subject | Handle windows mkdir |
commit 58cd29ae1d8bc4c8cdde76e511cea65b59b05115
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2026-05-27T15:07:32Z
Handle windows mkdir
---
README.md | 21 ++++++---------------
TODO | 2 +-
src/compat_file.h | 25 +++++++++++++++++++++++++
src/env.c | 21 ++++++++++++++++++++-
src/udp_route.c | 3 ++-
5 files changed, 54 insertions(+), 18 deletions(-)
diff --git a/README.md b/README.md
index c12158d..e2742d7 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# tinyproxy
-This is a work-in-progress tiny L4 proxy.
+A tiny L4 proxy.
The goal is not to become HAProxy, Envoy, nginx, or a general-purpose load balancer but to stay small and practical for simple inetd-style forwarding tasks.
@@ -8,10 +8,9 @@ The goal is not to become HAProxy, Envoy, nginx, or a general-purpose load balan
1. Should feel like an inet utility.
2. Be simple and effective.
-3. Run in the foreground.
-4. Use libevent2 for readability and future maintainability.
-5. Prefer explicit behavior over magic.
-6. Avoid protocol-specific features unless they are small and practical.
+3. Be explicit and performant
+4. Run in the foreground.
+5. Avoid protocol-specific features unless they are small and practical.
## Configuration
@@ -51,6 +50,8 @@ Run with:
tinyproxy -c tinyproxy.conf
```
+check tinyproxy.conf for a more complete setup
+
## Supported protocols
### TCP
@@ -138,13 +139,3 @@ Use HAProxy, Envoy, nginx, Cilium, or a real load balancer if you need those.
## Development status
This project is still experimental.
-
-Currently tested areas include:
-
-- TCP roundtrip forwarding
-- TCP stress forwarding
-- TCP Proxy Protocol v2 forwarding
-- UDP roundtrip forwarding
-- UDP Proxy Protocol v2 forwarding
-
-Expect rough edges.
diff --git a/TODO b/TODO
index 333c05c..5d0e134 100644
--- a/TODO
+++ b/TODO
@@ -3,4 +3,4 @@
## Forwarding
* IPv6
-* unix socks
+* unix socks (listen)
diff --git a/src/compat_file.h b/src/compat_file.h
new file mode 100644
index 0000000..68087ae
--- /dev/null
+++ b/src/compat_file.h
@@ -0,0 +1,25 @@
+#ifndef COMPAT_FILE_H
+#define COMPAT_FILE_H
+
+#ifdef _WIN32
+#include <direct.h>
+#include <errno.h>
+
+static inline int compat_mkdir(const char *path, int mode)
+{
+ (void)mode;
+ return _mkdir(path);
+}
+
+#else
+#include <sys/stat.h>
+#include <sys/types.h>
+
+static inline int compat_mkdir(const char *path, mode_t mode)
+{
+ return mkdir(path, mode);
+}
+
+#endif
+
+#endif
diff --git a/src/env.c b/src/env.c
index 08b9381..27a9bd4 100644
--- a/src/env.c
+++ b/src/env.c
@@ -2,15 +2,34 @@
#include <stdlib.h>
+#ifdef _WIN32
+#define TINYPROXY_DEFAULT_RUNTIME_DIR "tinyproxy"
+#else
#define TINYPROXY_DEFAULT_RUNTIME_DIR "/tmp/tinyproxy"
+#endif
const char *tinyproxy_runtime_dir(void)
{
- const char *v = getenv("TINYPROXY_RUNTIME_DIR");
+ const char *v;
+ v = getenv("TINYPROXY_RUNTIME_DIR");
if (v != NULL && v[0] != '\0') {
return v;
}
+#ifndef _WIN32
return TINYPROXY_DEFAULT_RUNTIME_DIR;
+#else
+ v = getenv("TEMP");
+ if (v != NULL && v[0] != '\0') {
+ return v;
+ }
+
+ v = getenv("TMP");
+ if (v != NULL && v[0] != '\0') {
+ return v;
+ }
+
+ return ".";
+#endif
}
diff --git a/src/udp_route.c b/src/udp_route.c
index 5bc9690..285f987 100644
--- a/src/udp_route.c
+++ b/src/udp_route.c
@@ -12,6 +12,7 @@
#include "env.h"
#include "file_conf.h"
#include "compat_socket.h"
+#include "compat_file.h"
#include "proxy_proto_v2.h"
#include "route.h"
#include "udp_route.h"
@@ -488,7 +489,7 @@ int start_udp_route(
if (r->upstream.kind == ENDPOINT_UNIX_DGRAM) {
const char *runtime_dir = tinyproxy_runtime_dir();
- if (mkdir(runtime_dir, 0755) < 0 && errno != EEXIST) {
+ if (compat_mkdir(runtime_dir, 0755) < 0 && errno != EEXIST) {
LOG_ERROR("failed to create unix-dgram runtime dir",
"dir", _LOGV(runtime_dir),
"err", _LOGV(strerror(errno))