OSSP CVS Repository

ossp - Difference in ossp-pkg/sa/sa.c versions 1.64 and 1.65
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/sa/sa.c 1.64 -> 1.65

--- sa.c 2002/10/30 09:21:52     1.64
+++ sa.c 2002/10/30 19:09:35     1.65
@@ -2183,6 +2183,46 @@
     return SA_OK;
 }
 
+/* send formatted string to socket (convinience function) */
+sa_rc_t sa_sendf(sa_t *sa, sa_addr_t *raddr, const char *cpFmt, ...)
+{
+    va_list ap;
+    size_t nBuf;
+    char *cpBuf;
+    sa_rc_t rv;
+    char caBuf[1024];
+
+    /* argument sanity check(s) */
+    if (sa == NULL || raddr == NULL || cpFmt == NULL)
+        return SA_RC(SA_ERR_ARG);
+
+    /* format string into temporary buffer */
+    va_start(ap, cpFmt);
+    nBuf = sa_mvsnprintf(NULL, NULL, cpFmt, ap);
+    va_end(ap);
+    if ((nBuf+1) > sizeof(caBuf)) {
+        /* requires a larger buffer, so allocate dynamically */
+        if ((cpBuf = (char *)malloc(nBuf+1)) == NULL)
+            return SA_RC(SA_ERR_SYS);
+    }
+    else {
+        /* fits into small buffer, so allocate statically */
+        cpBuf = caBuf;
+    }
+    va_start(ap, cpFmt);
+    sa_mvsnprintf(cpBuf, nBuf+1, cpFmt, ap);
+    va_end(ap);
+
+    /* pass-through to sa_send() */
+    rv = sa_send(sa, cpBuf, nBuf, NULL, raddr);
+
+    /* cleanup dynamically allocated buffer */
+    if ((nBuf+1) > sizeof(caBuf))
+        free(cpBuf);
+
+    return rv;
+}
+
 /* return error string */
 char *sa_error(sa_rc_t rv)
 {

CVSTrac 2.0.1