summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2010-05-12 20:03:38 +0200
committerJohannes Weiner <hannes@cmpxchg.org>2010-05-12 20:05:34 +0200
commitf15144e93318b1a92c037f7481d85456978fefef (patch)
tree6c946837d1d0bc79885d25eaf6bc4383393a9d56
parentb215cf006f82b9fa0dfe3f4925ea00641330aad3 (diff)
lib: library fixes for string changes
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
-rw-r--r--lib/io.c13
-rw-r--r--lib/regex.c6
-rw-r--r--lib/sha1.c4
3 files changed, 12 insertions, 11 deletions
diff --git a/lib/io.c b/lib/io.c
index 81cea1e..3dfbe1f 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -49,8 +49,8 @@ static const struct sheep_type file_type = {
/* (open pathname mode) */
static sheep_t open(struct sheep_vm *vm, unsigned int nr_args)
{
+ struct sheep_string *path;
struct file *file;
- const char *path;
sheep_t write;
FILE *filp;
@@ -58,12 +58,12 @@ static sheep_t open(struct sheep_vm *vm, unsigned int nr_args)
return NULL;
if (sheep_test(write))
- filp = fopen(path, "w");
+ filp = fopen(path->bytes, "w");
else
- filp = fopen(path, "r");
+ filp = fopen(path->bytes, "r");
if (!filp) {
- fprintf(stderr, "%s: can not open file\n", path);
+ fprintf(stderr, "%s: can not open file\n", path->bytes);
return NULL;
}
@@ -112,8 +112,8 @@ static sheep_t read(struct sheep_vm *vm, unsigned int nr_args)
/* (write file string) */
static sheep_t write(struct sheep_vm *vm, unsigned int nr_args)
{
+ struct sheep_string *string;
unsigned long nr_bytes;
- const char *string;
struct file *file;
if (sheep_unpack_stack(vm, nr_args, "TS", &file_type, &file, &string))
@@ -124,8 +124,7 @@ static sheep_t write(struct sheep_vm *vm, unsigned int nr_args)
return NULL;
}
- nr_bytes = strlen(string);
- nr_bytes = fwrite(string, 1, nr_bytes, file->filp);
+ nr_bytes = fwrite(string->bytes, 1, string->nr_bytes, file->filp);
return sheep_make_number(vm, nr_bytes);
}
diff --git a/lib/regex.c b/lib/regex.c
index db42acb..897b4c9 100644
--- a/lib/regex.c
+++ b/lib/regex.c
@@ -22,17 +22,19 @@
static sheep_t match(struct sheep_vm *vm, unsigned int nr_args)
{
regmatch_t matches[MAX_MATCHES];
- sheep_t string_, result = NULL;
+ sheep_t regex_, string_, result = NULL;
const char *regex, *string;
struct sheep_list *list;
unsigned int i;
regex_t reg;
int status;
- if (sheep_unpack_stack(vm, nr_args, "Ss", &regex, &string_))
+ if (sheep_unpack_stack(vm, nr_args, "ss", &regex_, &string_))
return NULL;
+
sheep_protect(vm, string_);
+ regex = sheep_rawstring(regex_);
if (regcomp(&reg, regex, REG_EXTENDED)) {
fprintf(stderr, "match: invalid regular expression\n");
goto out;
diff --git a/lib/sha1.c b/lib/sha1.c
index 341ad33..8665c23 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -11,13 +11,13 @@ static sheep_t sha1(struct sheep_vm *vm, unsigned int nr_args)
{
char hexdigest[SHA_DIGEST_LENGTH * 2 + 1];
unsigned char hash[SHA_DIGEST_LENGTH];
- const char *text;
+ struct sheep_string *text;
unsigned int i;
if (sheep_unpack_stack(vm, nr_args, "S", &text))
return NULL;
- SHA1((const unsigned char *)text, strlen(text), hash);
+ SHA1((const unsigned char *)text->bytes, text->nr_bytes, hash);
for (i = 0; i < SHA_DIGEST_LENGTH; i++)
sprintf(hexdigest + i * 2, "%02x", hash[i]);