From 5f4a5f59b072d4029107422d30b04941424c48b1 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Tue, 24 Feb 2015 02:52:05 +0000
Subject: [PATCH] captcha stuff
---
src/utils.c | 33 +++++++++++++++++++++++++++++++++
1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/src/utils.c b/src/utils.c
index 8261682..1db8101 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -2,11 +2,23 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
+#include <unistd.h>
#include <float.h>
#include <limits.h>
#include "utils.h"
+
+int alphanum_to_int(char c)
+{
+ return (c < 58) ? c - 48 : c-87;
+}
+char int_to_alphanum(int i)
+{
+ if (i == 36) return '.';
+ return (i < 10) ? i + 48 : i + 87;
+}
+
void pm(int M, int N, float *A)
{
int i,j;
@@ -148,6 +160,27 @@
return line;
}
+void read_all(int fd, char *buffer, size_t bytes)
+{
+ size_t n = 0;
+ while(n < bytes){
+ int next = read(fd, buffer + n, bytes-n);
+ if(next <= 0) error("read failed");
+ n += next;
+ }
+}
+
+void write_all(int fd, char *buffer, size_t bytes)
+{
+ size_t n = 0;
+ while(n < bytes){
+ size_t next = write(fd, buffer + n, bytes-n);
+ if(next <= 0) error("write failed");
+ n += next;
+ }
+}
+
+
char *copy_string(char *s)
{
char *copy = malloc(strlen(s)+1);
--
Gitblit v1.10.0