-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring-crypt.c
More file actions
34 lines (28 loc) · 854 Bytes
/
Copy pathstring-crypt.c
File metadata and controls
34 lines (28 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdlib.h>
#include <unistd.h>
#include <mruby.h>
#include <mruby/string.h>
#include <pthread.h>
extern char *crypt(const char *, const char *);
static mrb_value
mrb_string_crypt(mrb_state* mrb, mrb_value self) {
mrb_value str = mrb_nil_value();
static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
mrb_get_args(mrb, "S", &str);
if (pthread_mutex_lock(&m) == 0) {
mrb_value ret = mrb_nil_value();
char *res = crypt(mrb_str_to_cstr(mrb, self), mrb_str_to_cstr(mrb, str));
if (res) ret = mrb_str_new_cstr(mrb, res);
pthread_mutex_unlock(&m);
return ret;
}
return mrb_nil_value();
}
void
mrb_mruby_string_crypt_gem_init(mrb_state* mrb) {
mrb_define_module_function(mrb, mrb->string_class, "crypt", mrb_string_crypt, MRB_ARGS_REQ(1));
}
void
mrb_mruby_string_crypt_gem_final(mrb_state* mrb) {
(void)mrb;
}