[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 18/31] slirp: add slirp own version of pstrcpy
From: |
Samuel Thibault |
Subject: |
[Qemu-devel] [PULL 18/31] slirp: add slirp own version of pstrcpy |
Date: |
Sun, 27 Jan 2019 13:05:13 +0100 |
From: Marc-André Lureau <address@hidden>
Remove a dependency on qemu util.
Signed-off-by: Marc-André Lureau <address@hidden>
Signed-off-by: Samuel Thibault <address@hidden>
---
slirp/slirp.c | 4 ++--
slirp/tftp.c | 2 +-
slirp/util.c | 17 +++++++++++++++++
slirp/util.h | 2 ++
4 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 9ec1e4c62f..b5c4788489 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -320,8 +320,8 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct
in_addr vnetwork,
slirp->vprefix_len = vprefix_len;
slirp->vhost_addr6 = vhost6;
if (vhostname) {
- pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname),
- vhostname);
+ slirp_pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname),
+ vhostname);
}
slirp->tftp_prefix = g_strdup(tftp_path);
slirp->bootp_filename = g_strdup(bootfile);
diff --git a/slirp/tftp.c b/slirp/tftp.c
index 6fb381ef33..f0bcc72c92 100644
--- a/slirp/tftp.c
+++ b/slirp/tftp.c
@@ -216,7 +216,7 @@ static void tftp_send_error(struct tftp_session *spt,
tp->tp_op = htons(TFTP_ERROR);
tp->x.tp_error.tp_error_code = htons(errorcode);
- pstrcpy((char *)tp->x.tp_error.tp_msg, sizeof(tp->x.tp_error.tp_msg), msg);
+ slirp_pstrcpy((char *)tp->x.tp_error.tp_msg, sizeof(tp->x.tp_error.tp_msg),
msg);
m->m_len = sizeof(struct tftp_t) - (TFTP_BLOCKSIZE_MAX + 2) + 3 + strlen(msg)
- sizeof(struct udphdr);
diff --git a/slirp/util.c b/slirp/util.c
index 59f6713c8b..84f5afdbc3 100644
--- a/slirp/util.c
+++ b/slirp/util.c
@@ -188,3 +188,20 @@ int slirp_closesocket(int fd)
return ret;
}
#endif /* WIN32 */
+
+void slirp_pstrcpy(char *buf, int buf_size, const char *str)
+{
+ int c;
+ char *q = buf;
+
+ if (buf_size <= 0)
+ return;
+
+ for(;;) {
+ c = *str++;
+ if (c == 0 || q >= buf + buf_size - 1)
+ break;
+ *q++ = c;
+ }
+ *q = '\0';
+}
diff --git a/slirp/util.h b/slirp/util.h
index 4f6e80c3ed..586517bb30 100644
--- a/slirp/util.h
+++ b/slirp/util.h
@@ -91,4 +91,6 @@ static inline int slirp_socket_set_fast_reuse(int fd)
#endif
}
+void slirp_pstrcpy(char *buf, int buf_size, const char *str);
+
#endif
--
2.20.1
- [Qemu-devel] [PULL 23/31] slirp: replace QEMU_BUILD_BUG_ON with G_STATIC_ASSERT, (continued)
- [Qemu-devel] [PULL 23/31] slirp: replace QEMU_BUILD_BUG_ON with G_STATIC_ASSERT, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 09/31] slirp: replace trace functions with DEBUG calls, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 03/31] slirp: Don't mark struct ipq or struct ipasfrag as packed, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 16/31] slirp: do not include qemu headers in libslirp.h public API header, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 13/31] slirp: add unregister_poll_fd() callback, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 28/31] slirp: remove slirp_instances list, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 10/31] slirp: replace QEMU_PACKED with SLIRP_PACKED, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 12/31] slirp: replace qemu_set_nonblock(), Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 17/31] slirp: improve windows headers inclusion, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 15/31] slirp: move QEMU state saving to a separate unit, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 18/31] slirp: add slirp own version of pstrcpy,
Samuel Thibault <=
- [Qemu-devel] [PULL 21/31] slirp: replace net/eth.h inclusion with own defines, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 11/31] slirp: replace most qemu socket utilities with slirp own version, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 20/31] slirp: remove now useless QEMU headers inclusions, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 31/31] slirp: API is extern C, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 29/31] slirp: use polling callbacks, drop glib requirement, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 30/31] slirp: pass opaque to all callbacks, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 27/31] slirp: replace global polling with per-instance & notifier, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 24/31] slirp: replace remaining qemu headers dependency, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 22/31] slirp: replace qemu qtailq with slirp own copy, Samuel Thibault, 2019/01/27
- [Qemu-devel] [PULL 25/31] slirp: prefer c99 types over BSD kind, Samuel Thibault, 2019/01/27