#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
+#include <string.h>
#include <sys/time.h>
#include <rfb/util.h>
namespace rfb {
- void CharArray::format(const char *fmt, ...) {
- va_list ap;
- int len;
-
- va_start(ap, fmt);
- len = vsnprintf(NULL, 0, fmt, ap);
- va_end(ap);
-
- delete [] buf;
-
- if (len < 0) {
- buf = new char[1];
- buf[0] = '\0';
- return;
- }
-
- buf = new char[len+1];
-
- va_start(ap, fmt);
- vsnprintf(buf, len+1, fmt, ap);
- va_end(ap);
- }
-
char* strDup(const char* s) {
if (!s) return 0;
int l = strlen(s);
#define __RFB_UTIL_H__
#include <limits.h>
-#include <string.h>
#include <stdint.h>
#include <string>
namespace rfb {
- // -=- Class to handle cleanup of arrays of characters
- class CharArray {
- public:
- CharArray() : buf(0) {}
- CharArray(char* str) : buf(str) {} // note: assumes ownership
- CharArray(size_t len) {
- buf = new char[len]();
- memset(buf, 0, len);
- }
- ~CharArray() {
- delete [] buf;
- }
- void format(const char *fmt, ...)
- __attribute__((__format__ (__printf__, 2, 3)));
- // Get the buffer pointer & clear it (i.e. caller takes ownership)
- char* takeBuf() {char* tmp = buf; buf = 0; return tmp;}
- void replaceBuf(char* b) {delete [] buf; buf = b;}
- char* buf;
- private:
- CharArray(const CharArray&);
- CharArray& operator=(const CharArray&);
- };
-
char* strDup(const char* s);
void strFree(char* s);