add luaposix crypt() support
[project/luci.git] / contrib / luaposix / patches / 200-crypt.patch
1 Index: luaposix-5.1.2/lposix.c
2 ===================================================================
3 --- luaposix-5.1.2.orig/lposix.c        2008-06-02 17:35:21.000000000 +0200
4 +++ luaposix-5.1.2/lposix.c     2008-06-02 17:35:26.000000000 +0200
5 @@ -1006,6 +1006,29 @@
6  }
7  #endif
8  
9 +/*
10 + * XXX: GNU and BSD handle the forward declaration of crypt() in different
11 + * and annoying ways (especially GNU). Declare it here just to make sure
12 + * that it's there
13 + */
14 +char *crypt(const char *, const char *);
15 +
16 +static int Pcrypt(lua_State *L)
17 +{
18 +       const char *str, *salt;
19 +       char *res;
20 +
21 +       str = luaL_checkstring(L, 1);
22 +       salt = luaL_checkstring(L, 2);
23 +       if (strlen(salt) < 2)
24 +               luaL_error(L, "not enough salt");
25 +
26 +       res = crypt(str, salt);
27 +       lua_pushstring(L, res);
28 +
29 +       return 1;
30 +}
31 +
32  static const luaL_reg R[] =
33  {
34         {"access",              Paccess},
35 @@ -1013,6 +1036,7 @@
36         {"chdir",               Pchdir},
37         {"chmod",               Pchmod},
38         {"chown",               Pchown},
39 +       {"crypt",               Pcrypt},
40         {"ctermid",             Pctermid},
41         {"dirname",             Pdirname},
42         {"dir",                 Pdir},
43 Index: luaposix-5.1.2/Makefile
44 ===================================================================
45 --- luaposix-5.1.2.orig/Makefile        2008-06-02 17:35:26.000000000 +0200
46 +++ luaposix-5.1.2/Makefile     2008-06-02 17:35:18.000000000 +0200
47 @@ -37,8 +37,10 @@
48  OS=$(shell uname)
49  ifeq ($(OS),Darwin)
50    LDFLAGS_SHARED=-bundle -undefined dynamic_lookup
51 +  LIBS=
52  else
53    LDFLAGS_SHARED=-shared
54 +  LIBS=-lcrypt
55  endif
56  
57  # targets
58 @@ -50,7 +52,7 @@
59         $(LUA) test.lua
60  
61  $T:    $(OBJS)
62 -       $(CC) $(LDFLAGS) -o $@ $(LDFLAGS_SHARED) $(OBJS)
63 +       $(CC) $(LDFLAGS) -o $@ $(LDFLAGS_SHARED) $(OBJS) $(LIBS)
64  
65  $(OBJS): modemuncher.c
66