1 diff -Nbur lua-5.1.4.orig/src/Makefile lua-5.1.4/src/Makefile
2 --- lua-5.1.4.orig/src/Makefile 2009-04-06 21:36:52.000000000 +0200
3 +++ lua-5.1.4/src/Makefile 2009-04-11 01:02:45.000000000 +0200
5 lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
6 lundump.o lvm.o lzio.o lnum.o
7 LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \
8 - lstrlib.o loadlib.o linit.o
9 + lstrlib.o loadlib.o linit.o lar.o md5.o larlib.o
13 diff -Nbur lua-5.1.4.orig/src/lar.c lua-5.1.4/src/lar.c
14 --- lua-5.1.4.orig/src/lar.c 1970-01-01 01:00:00.000000000 +0100
15 +++ lua-5.1.4/src/lar.c 2009-04-13 16:51:07.000000000 +0200
18 + * lar - Lua Archive Library
20 + * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
22 + * Licensed under the Apache License, Version 2.0 (the "License");
23 + * you may not use this file except in compliance with the License.
24 + * You may obtain a copy of the License at
26 + * http://www.apache.org/licenses/LICENSE-2.0
28 + * Unless required by applicable law or agreed to in writing, software
29 + * distributed under the License is distributed on an "AS IS" BASIS,
30 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 + * See the License for the specific language governing permissions and
32 + * limitations under the License.
38 +static int lar_read32( int fd, uint32_t *val )
42 + if( read(fd, buffer, 4) < 4 )
43 + LAR_DIE("Unexpected EOF while reading data");
46 + *val = ntohl(*((uint32_t *) buffer));
51 +static int lar_read16( int fd, uint16_t *val )
55 + if( read(fd, buffer, 2) < 2 )
56 + LAR_DIE("Unexpected EOF while reading data");
59 + *val = ntohs(*((uint16_t *) buffer));
64 +static void lar_md5( char *md5, const char *data, int len )
69 + md5_append(&state, (const md5_byte_t *)data, len);
70 + md5_finish(&state, (md5_byte_t *)md5);
73 +static int lar_read_filenames( lar_archive *ar )
79 + size_t pgsz = getpagesize();
81 + lar_index *idx_filelist = ar->index;
85 + if( idx_filelist->type == LAR_TYPE_FILELIST )
88 + idx_filelist = idx_filelist->next;
91 + if( idx_filelist != NULL )
93 + pgof = ( idx_filelist->offset % pgsz );
96 + 0, idx_filelist->length + pgof, PROT_READ, MAP_PRIVATE,
97 + ar->fd, idx_filelist->offset - pgof
100 + if( filelist == MAP_FAILED )
101 + LAR_DIE("Failed to mmap() file list");
104 + idx_ptr = ar->index;
109 + if( idx_ptr->type == LAR_TYPE_REGULAR )
111 + j = strlen(&filelist[i]) + 1;
113 + if( (j >= LAR_FNAME_BUFFER) ||
114 + ((i+j) > (idx_filelist->length+pgof)) )
115 + LAR_DIE("Filename exceeds maximum allowed length");
117 + idx_ptr->filename = (char *)malloc(j);
118 + memcpy(idx_ptr->filename, &filelist[i], j);
123 + idx_ptr = idx_ptr->next;
126 + munmap(filelist, idx_filelist->length + pgof);
134 +lar_index * lar_get_index( lar_archive *ar )
137 + uint32_t idx_offset;
138 + uint32_t idx_length;
139 + lar_index *idx_map;
140 + lar_index *idx_ptr;
142 + if( lseek(ar->fd, -(sizeof(idx_offset)), SEEK_END) == -1 )
143 + LAR_DIE("Unable to seek to end of archive");
145 + lar_read32(ar->fd, &idx_offset);
146 + idx_length = ( ar->length - idx_offset - sizeof(idx_offset) );
148 + if( lseek(ar->fd, idx_offset, SEEK_SET) == -1 )
149 + LAR_DIE("Unable to seek to archive index");
154 + for( i = 0; i < idx_length; i += (sizeof(lar_index) - 2 * sizeof(char *)) )
156 + idx_ptr = (lar_index *)malloc(sizeof(lar_index));
157 + idx_ptr->filename = NULL;
159 + lar_read32(ar->fd, &idx_ptr->offset);
160 + lar_read32(ar->fd, &idx_ptr->length);
161 + lar_read16(ar->fd, &idx_ptr->type);
162 + lar_read16(ar->fd, &idx_ptr->flags);
164 + if(read(ar->fd,&idx_ptr->id,sizeof(idx_ptr->id)) < sizeof(idx_ptr->id))
165 + LAR_DIE("Unexpected EOF while reading member id");
167 + idx_ptr->next = idx_map;
174 +lar_member * lar_mmap_member( lar_archive *ar, lar_index *idx_ptr )
176 + lar_member *member;
177 + size_t pgsz = getpagesize();
178 + size_t pgof = ( idx_ptr->offset % pgsz );
180 + char *memberdata = mmap(
181 + 0, idx_ptr->length + pgof, PROT_READ, MAP_PRIVATE,
182 + ar->fd, idx_ptr->offset - pgof
185 + if( memberdata == MAP_FAILED )
186 + LAR_DIE("Failed to mmap() member data");
188 + member = (lar_member *)malloc(sizeof(lar_member));
189 + member->type = idx_ptr->type;
190 + member->flags = idx_ptr->flags;
191 + member->length = idx_ptr->length;
192 + member->data = &memberdata[pgof];
194 + member->mmap = memberdata;
195 + member->mlen = idx_ptr->length + pgof;
200 +lar_member * lar_open_member( lar_archive *ar, const char *name )
202 + lar_index *idx_ptr = ar->index;
203 + char mbid[sizeof(idx_ptr->id)];
205 + lar_md5(mbid, name, strlen(name));
209 + if( !strncmp(mbid, idx_ptr->id, sizeof(mbid)) )
210 + return lar_mmap_member(ar, idx_ptr);
212 + idx_ptr = idx_ptr->next;
218 +int lar_close_member( lar_member *member )
220 + int stat = munmap(member->mmap, member->mlen);
227 +lar_archive * lar_open( const char *filename )
233 + if( stat(filename, &as) == -1 )
236 + if( !(as.st_mode & S_IFREG) )
239 + if( (fd = open(filename, O_RDONLY)) != -1 )
241 + ar = (lar_archive *)malloc(sizeof(lar_archive));
243 + ar->length = as.st_size;
244 + ar->index = lar_get_index(ar);
245 + strncpy(ar->filename, filename, sizeof(ar->filename));
247 + ar->has_filenames = lar_read_filenames(ar);
255 +int lar_close( lar_archive *ar )
257 + lar_index *idx_head;
258 + lar_index *idx_next;
262 + idx_head = ar->index;
264 + idx_next = idx_head->next;
265 + free(idx_head->filename);
267 + } while( (idx_head = idx_next) != NULL );
275 +lar_archive * lar_find_archive( const char *package, const char *path, int pkg )
282 + char sep = ( pkg ? '.' : '/' );
288 + for( pln = 0; path[pln] != '\0'; pln++ )
289 + if( pln >= (sizeof(buffer) - 5) )
290 + LAR_DIE("Library path exceeds maximum allowed length");
292 + memcpy(buffer, path, pln);
295 + if( buffer[pln-1] != '/' )
296 + buffer[pln++] = '/';
298 + for( len = 0; package[len] != '\0'; len++ )
300 + if( len >= (sizeof(buffer) - 5 - pln) )
301 + LAR_DIE("Package name exceeds maximum allowed length");
303 + if( package[len] == sep ) seg++;
308 + for( i = 0, j = 1; (i < len) && (j <= seg); i++ )
310 + if( package[i] == sep ) {
311 + if( j < seg ) j++; else break;
314 + buffer[pln+i] = ( package[i] == sep ) ? LAR_DIRSEP : package[i];
317 + strcpy(&buffer[pln+i], ".lar");
319 + if( (stat(buffer, &s) > -1) && (s.st_mode & S_IFREG) )
320 + return lar_open(buffer);
328 +lar_member * lar_find_member( lar_archive *ar, const char *package )
333 + for( len = 0; package[len] != '\0'; len++ )
335 + if( len >= (sizeof(buffer) - 5) )
336 + LAR_DIE("Package name exceeds maximum allowed length");
338 + buffer[len] = ( package[len] == '.' ) ? '/' : package[len];
341 + strcpy(&buffer[len], ".lua");
343 + return lar_open_member(ar, buffer);
345 diff -Nbur lua-5.1.4.orig/src/lar.h lua-5.1.4/src/lar.h
346 --- lua-5.1.4.orig/src/lar.h 1970-01-01 01:00:00.000000000 +0100
347 +++ lua-5.1.4/src/lar.h 2009-04-13 16:51:32.000000000 +0200
350 + * lar - Lua Archive Library
352 + * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
354 + * Licensed under the Apache License, Version 2.0 (the "License");
355 + * you may not use this file except in compliance with the License.
356 + * You may obtain a copy of the License at
358 + * http://www.apache.org/licenses/LICENSE-2.0
360 + * Unless required by applicable law or agreed to in writing, software
361 + * distributed under the License is distributed on an "AS IS" BASIS,
362 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
363 + * See the License for the specific language governing permissions and
364 + * limitations under the License.
378 +#include <arpa/inet.h>
379 +#include <sys/types.h>
380 +#include <sys/mman.h>
381 +#include <sys/stat.h>
385 +#define LAR_DIE(s) \
387 + fprintf(stderr, "%s(%i): %s(): %s\n", \
388 + __FILE__, __LINE__, __FUNCTION__, s); \
389 + if( errno ) fprintf(stderr, "%s(%i): %s\n", \
390 + __FILE__, __LINE__, strerror(errno) ); \
395 +#define LAR_FNAME_BUFFER 1024
396 +#define LAR_FNAME(s) char s[LAR_FNAME_BUFFER]
398 +#define LAR_TYPE_REGULAR 0x0000
399 +#define LAR_TYPE_FILELIST 0xFFFF
402 +#define LAR_DIRSEP '\\'
404 +#define LAR_DIRSEP '/'
408 +struct lar_index_item {
415 + struct lar_index_item *next;
418 +struct lar_member_item {
427 +struct lar_archive_handle {
431 + char filename[LAR_FNAME_BUFFER];
432 + struct lar_index_item *index;
435 +typedef struct lar_index_item lar_index;
436 +typedef struct lar_member_item lar_member;
437 +typedef struct lar_archive_handle lar_archive;
440 +static int lar_read_filenames( lar_archive *ar );
441 +static int lar_read32( int fd, uint32_t *val );
442 +static int lar_read16( int fd, uint16_t *val );
443 +static void lar_md5( char *md5, const char *data, int len );
446 +lar_index * lar_get_index( lar_archive *ar );
448 +lar_member * lar_mmap_member( lar_archive *ar, lar_index *idx_ptr );
450 +lar_member * lar_open_member( lar_archive *ar, const char *name );
452 +int lar_close_member( lar_member *member );
454 +lar_archive * lar_open( const char *filename );
456 +int lar_close( lar_archive *ar );
458 +lar_archive * lar_find_archive( const char *package, const char *path, int pkg);
460 +lar_member * lar_find_member( lar_archive *ar, const char *package );
463 diff -Nbur lua-5.1.4.orig/src/larlib.c lua-5.1.4/src/larlib.c
464 --- lua-5.1.4.orig/src/larlib.c 1970-01-01 01:00:00.000000000 +0100
465 +++ lua-5.1.4/src/larlib.c 2009-04-13 16:51:15.000000000 +0200
468 + * lar - Lua Archive Library
470 + * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
472 + * Licensed under the Apache License, Version 2.0 (the "License");
473 + * you may not use this file except in compliance with the License.
474 + * You may obtain a copy of the License at
476 + * http://www.apache.org/licenses/LICENSE-2.0
478 + * Unless required by applicable law or agreed to in writing, software
479 + * distributed under the License is distributed on an "AS IS" BASIS,
480 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
481 + * See the License for the specific language governing permissions and
482 + * limitations under the License.
488 +#include "lauxlib.h"
497 +static int larlib_perror( lua_State *L, const char *message )
500 + lua_pushstring(L, message);
505 +int larlib_open( lua_State *L )
507 + lar_archive *ar, **udata;
508 + const char *filename = luaL_checkstring( L, 1 );
510 + if( filename != NULL && (ar = lar_open(filename)) != NULL )
512 + if( (udata = lua_newuserdata(L, sizeof(lar_archive *))) != NULL )
515 + luaL_getmetatable(L, "lar.archive");
516 + lua_setmetatable(L, -2);
520 + return luaL_error(L, "Out of memory");
525 + return larlib_perror(L, "Archive not found");
531 +int larlib_find( lua_State *L )
533 + const char *filename = luaL_checkstring( L, 1 );
534 + const char *basepath = luaL_optstring( L, 2, "./" );
535 + int is_pkg = strstr(filename, "/") ? 0 : 1;
536 + lar_archive *ar, **udata;
538 + if( ((ar = lar_find_archive(filename, basepath, is_pkg)) != NULL) ||
539 + ((ar = lar_find_archive(filename, LUA_LDIR, is_pkg)) != NULL) ||
540 + ((ar = lar_find_archive(filename, LUA_CDIR, is_pkg)) != NULL) )
542 + if( (udata = lua_newuserdata(L, sizeof(lar_archive *))) != NULL )
545 + luaL_getmetatable(L, "lar.archive");
546 + lua_setmetatable(L, -2);
550 + return luaL_error(L, "Out of memory");
555 + return larlib_perror(L, "Archive not found");
561 +int larlib_md5( lua_State *L )
564 + char md5[16], md5_hex[33];
565 + const char *data = luaL_checkstring( L, 1 );
569 + md5_append(&state, (const md5_byte_t *)data, strlen(data));
570 + md5_finish(&state, (md5_byte_t *)md5);
572 + for( i = 0; i < 16; i++ )
573 + sprintf(&md5_hex[i*2], "%02x", (unsigned char)md5[i]);
575 + lua_pushstring(L, md5_hex);
579 +int larlib_md5_file( lua_State *L )
582 + char md5[16], md5_hex[33], buffer[1024];
583 + const char *filename = luaL_checkstring( L, 1 );
586 + if( (fd = open(filename, O_RDONLY)) != -1 )
590 + while( (len = read(fd, buffer, 1024)) > 0 )
591 + md5_append(&state, (const md5_byte_t *)buffer, len);
593 + md5_finish(&state, (md5_byte_t *)md5);
595 + for( i = 0; i < 16; i++ )
596 + sprintf(&md5_hex[i*2], "%02x", (unsigned char)md5[i]);
599 + lua_pushstring(L, md5_hex);
603 + return larlib_perror(L, strerror(errno));
609 +static int larlib_mkpath( const char *name, const char *path, char *buffer )
611 + int nlen = strlen(name);
612 + int plen = strlen(path);
614 + if( (nlen + plen + 1) <= 1024 )
616 + strcpy(buffer, path);
618 + if( buffer[plen-1] != '/' )
619 + buffer[plen++] = '/';
621 + strcpy(&buffer[plen], name);
622 + buffer[plen + nlen] = '\0';
630 +static int larlib__gc( lua_State *L )
632 + lar_archive **archive = luaL_checkudata( L, 1, "lar.archive" );
635 + lar_close(*archive);
642 +static int larlib_member__open( lua_State *L, lar_member *mb )
644 + lar_archive **archive = NULL;
645 + const char *filename = NULL;
646 + lar_member **udata;
650 + *archive = luaL_checkudata( L, 1, "lar.archive" );
651 + filename = luaL_checkstring( L, 2 );
654 + if( mb != NULL || (mb = lar_open_member(*archive, filename)) != NULL )
656 + if( (udata = lua_newuserdata(L, sizeof(lar_member *))) != NULL )
659 + luaL_getmetatable(L, "lar.member");
660 + lua_setmetatable(L, -2);
664 + return luaL_error(L, "Out of memory");
669 + return larlib_perror(L, "Member not found in archive");
675 +int larlib_member_open( lua_State *L )
677 + return larlib_member__open( L, NULL );
680 +int larlib_member_find( lua_State *L )
682 + lar_archive **archive = luaL_checkudata( L, 1, "lar.archive" );
683 + const char *package = luaL_checkstring( L, 2 );
684 + lar_member *mb, **udata;
686 + if( (mb = lar_find_member(*archive, package)) != NULL )
688 + if( (udata = lua_newuserdata(L, sizeof(lar_member *))) != NULL )
691 + luaL_getmetatable(L, "lar.member");
692 + lua_setmetatable(L, -2);
696 + return luaL_error(L, "Out of memory");
701 + return larlib_perror(L, "Member not found in archive");
707 +int larlib_member_size( lua_State *L )
709 + lar_member **member = luaL_checkudata( L, 1, "lar.member" );
710 + lua_pushnumber(L, (*member)->length);
714 +int larlib_member_type( lua_State *L )
716 + lar_member **member = luaL_checkudata( L, 1, "lar.member" );
717 + lua_pushnumber(L, (*member)->type);
721 +int larlib_member_flags( lua_State *L )
723 + lar_member **member = luaL_checkudata( L, 1, "lar.member" );
724 + lua_pushnumber(L, (*member)->flags);
728 +int larlib_member_read( lua_State *L )
730 + lar_member **member = luaL_checkudata( L, 1, "lar.member" );
731 + int start = luaL_checknumber( L, 2 );
732 + int length = luaL_optnumber( L, 3, (*member)->length );
735 + if( (start >= 0) && (start < (*member)->length) && (length > 0) )
737 + if( (start + length) >= (*member)->length )
738 + length = (*member)->length - start;
740 + if( (stringcopy = (char *)malloc(length + 1)) != NULL )
742 + memcpy(stringcopy, &(*member)->data[start], length);
743 + stringcopy[length] = '\0';
744 + lua_pushstring(L, stringcopy);
749 + return luaL_error(L, "Out of memory");
754 + return larlib_perror(L, "Invalid argument");
760 +int larlib_member_data( lua_State *L )
762 + lar_member **member = luaL_checkudata( L, 1, "lar.member" );
763 + lua_pushstring(L, (*member)->data);
767 +int larlib_member_load( lua_State *L )
769 + lar_member **member = luaL_checkudata( L, 1, "lar.member" );
770 + int status = luaL_loadbuffer( L, (*member)->data, (*member)->length,
783 +static int larlib_member__gc( lua_State *L )
785 + lar_member **member = luaL_checkudata( L, 1, "lar.member" );
788 + lar_close_member(*member);
795 +static int larlib_mmfile__open( lua_State *L, const char *filename )
798 + mmap_handle *fh, **udata;
800 + if( filename == NULL )
801 + filename = (const char *)luaL_checkstring( L, 1 );
803 + if( (fh = (mmap_handle *)malloc(sizeof(mmap_handle))) == NULL )
804 + return larlib_perror(L, "Out of memory");
806 + if( stat(filename, &s) > -1 && (fh->fd = open(filename, O_RDONLY)) > -1 )
808 + fh->length = s.st_size;
809 + fh->data = mmap( 0, s.st_size, PROT_READ, MAP_PRIVATE, fh->fd, 0 );
811 + if( fh->data == MAP_FAILED )
812 + return larlib_perror(L, "Failed to mmap() file");
814 + if( (udata = lua_newuserdata(L, sizeof(char *))) != NULL )
817 + luaL_getmetatable(L, "lar.mmfile");
818 + lua_setmetatable(L, -2);
822 + return larlib_perror(L, "Out of memory");
827 + return larlib_perror(L, strerror(errno));
833 +int larlib_mmfile_open( lua_State *L )
835 + return larlib_mmfile__open(L, NULL);
838 +int larlib_mmfile_size( lua_State *L )
840 + mmap_handle **fh = luaL_checkudata( L, 1, "lar.mmfile" );
841 + lua_pushnumber(L, (*fh)->length);
845 +int larlib_mmfile_read( lua_State *L )
847 + mmap_handle **fh = luaL_checkudata( L, 1, "lar.mmfile" );
848 + int start = luaL_checknumber( L, 2 );
849 + int length = luaL_optnumber( L, 3, (*fh)->length );
852 + if( (start >= 0) && (start < (*fh)->length) && (length > 0) )
854 + if( (start + length) >= (*fh)->length )
855 + length = (*fh)->length - start;
857 + if( (stringcopy = (char *)malloc(length + 1)) != NULL )
859 + memcpy(stringcopy, &(*fh)->data[start], length);
860 + stringcopy[length] = '\0';
861 + lua_pushstring(L, stringcopy);
866 + return luaL_error(L, "Out of memory");
871 + return larlib_perror(L, "Invalid argument");
877 +int larlib_mmfile_data( lua_State *L )
879 + mmap_handle **fh = luaL_checkudata( L, 1, "lar.mmfile" );
880 + lua_pushstring(L, (*fh)->data);
884 +int larlib_mmfile_load( lua_State *L )
886 + mmap_handle **fh = luaL_checkudata( L, 1, "lar.mmfile" );
887 + int status = luaL_loadbuffer(L, (*fh)->data, (*fh)->length, "=(mmap file)");
899 +static int larlib_mmfile__gc( lua_State *L )
901 + mmap_handle **fh = luaL_checkudata( L, 1, "lar.mmfile" );
906 + munmap((*fh)->data, (*fh)->length);
915 +int larlib_findfile( lua_State *L )
918 + const char *filename = luaL_checkstring( L, 1 );
919 + const char *basepath = luaL_optstring( L, 2, "./" );
920 + char filepath[1024];
925 + const char *searchpath[3] = { basepath, LUA_LDIR, LUA_CDIR };
927 + for( i = 0; i < 3; i++ )
928 + if( !larlib_mkpath(filename, searchpath[i], filepath) )
929 + if( stat(filepath, &s) > -1 && (s.st_mode & S_IFREG) )
930 + return larlib_mmfile__open( L, filepath );
932 + for( i = 0; i < 3; i++ )
933 + if( (ar = lar_find_archive(filename, searchpath[i], 0)) != NULL )
934 + if( (mb = lar_open_member(ar, filename)) != NULL )
935 + return larlib_member__open( L, mb );
937 + return larlib_perror(L, "File not found");
941 +static const luaL_reg LAR_REG[] = {
942 + { "open", larlib_open },
943 + { "find", larlib_find },
944 + { "md5", larlib_md5 },
945 + { "md5_file", larlib_md5_file },
946 + { "mmap", larlib_mmfile_open },
947 + { "findfile", larlib_findfile },
951 +static const luaL_reg LAR_ARCHIVE_REG[] = {
952 + { "member", larlib_member_open },
953 + { "find", larlib_member_find },
954 + { "__gc", larlib__gc },
958 +static const luaL_reg LAR_MEMBER_REG[] = {
959 + { "size", larlib_member_size },
960 + { "type", larlib_member_type },
961 + { "flags", larlib_member_flags },
962 + { "read", larlib_member_read },
963 + { "data", larlib_member_data },
964 + { "load", larlib_member_load },
965 + { "__gc", larlib_member__gc },
969 +static const luaL_reg LAR_MMFILE_REG[] = {
970 + { "size", larlib_mmfile_size },
971 + { "read", larlib_mmfile_read },
972 + { "data", larlib_mmfile_data },
973 + { "load", larlib_mmfile_load },
974 + { "__gc", larlib_mmfile__gc },
979 +LUALIB_API int luaopen_larlib( lua_State *L )
981 + luaL_newmetatable(L, "lar");
982 + luaL_register(L, NULL, LAR_REG);
983 + lua_pushvalue(L, -1);
984 + lua_setfield(L, -2, "__index");
985 + lua_setglobal(L, "lar");
987 + luaL_newmetatable(L, "lar.archive");
988 + luaL_register(L, NULL, LAR_ARCHIVE_REG);
989 + lua_pushvalue(L, -1);
990 + lua_setfield(L, -2, "__index");
991 + lua_setglobal(L, "lar.archive");
993 + luaL_newmetatable(L, "lar.member");
994 + luaL_register(L, NULL, LAR_MEMBER_REG);
995 + lua_pushvalue(L, -1);
996 + lua_setfield(L, -2, "__index");
997 + lua_setglobal(L, "lar.member");
999 + luaL_newmetatable(L, "lar.mmfile");
1000 + luaL_register(L, NULL, LAR_MMFILE_REG);
1001 + lua_pushvalue(L, -1);
1002 + lua_setfield(L, -2, "__index");
1003 + lua_setglobal(L, "lar.mmfile");
1007 diff -Nbur lua-5.1.4.orig/src/linit.c lua-5.1.4/src/linit.c
1008 --- lua-5.1.4.orig/src/linit.c 2009-04-06 21:36:52.000000000 +0200
1009 +++ lua-5.1.4/src/linit.c 2009-04-11 01:27:00.000000000 +0200
1011 {LUA_STRLIBNAME, luaopen_string},
1012 {LUA_MATHLIBNAME, luaopen_math},
1013 {LUA_DBLIBNAME, luaopen_debug},
1014 + {LUA_LARLIBNAME, luaopen_larlib},
1018 diff -Nbur lua-5.1.4.orig/src/loadlib.c lua-5.1.4/src/loadlib.c
1019 --- lua-5.1.4.orig/src/loadlib.c 2009-04-06 21:36:52.000000000 +0200
1020 +++ lua-5.1.4/src/loadlib.c 2009-04-11 01:04:47.000000000 +0200
1022 #include "lauxlib.h"
1027 /* prefix for open functions in C libraries */
1028 #define LUA_POF "luaopen_"
1029 @@ -388,6 +389,36 @@
1033 +static int loader_Lar (lua_State *L) {
1036 + const char *name = luaL_checkstring(L, 1);
1038 + if( (ar = lar_find_archive(name, "./", 1)) ||
1039 + (ar = lar_find_archive(name, LUA_LDIR, 1)) ||
1040 + (ar = lar_find_archive(name, LUA_CDIR, 1))
1042 + if( (mb = lar_find_member(ar, name)) != NULL ) {
1043 + if( luaL_loadbuffer(L, mb->data, mb->length, ar->filename) != 0 ) {
1044 + luaL_error(L, "error while loading lar member '%s':\n\t%s",
1045 + name, lua_tostring(L, -1));
1047 + lar_close_member(mb);
1050 + lua_pushfstring(L, "\n\tno matching lar member " LUA_QS " in " LUA_QS,
1051 + name, ar->filename);
1056 + lua_pushfstring(L, "\n\tno matching lar archive for " LUA_QS, name);
1063 static const char *mkfuncname (lua_State *L, const char *modname) {
1064 const char *funcname;
1065 const char *mark = strchr(modname, *LUA_IGMARK);
1069 static const lua_CFunction loaders[] =
1070 - {loader_preload, loader_Lua, loader_C, loader_Croot, NULL};
1071 + {loader_preload, loader_Lua, loader_Lar, loader_C, loader_Croot, NULL};
1074 LUALIB_API int luaopen_package (lua_State *L) {
1075 diff -Nbur lua-5.1.4.orig/src/lualib.h lua-5.1.4/src/lualib.h
1076 --- lua-5.1.4.orig/src/lualib.h 2009-04-06 21:36:52.000000000 +0200
1077 +++ lua-5.1.4/src/lualib.h 2009-04-11 01:28:24.000000000 +0200
1079 #define LUA_LOADLIBNAME "package"
1080 LUALIB_API int (luaopen_package) (lua_State *L);
1082 +#define LUA_LARLIBNAME "lar"
1083 +LUALIB_API int (luaopen_larlib) (lua_State *L);
1086 /* open all previous libraries */
1087 LUALIB_API void (luaL_openlibs) (lua_State *L);
1088 diff -Nbur lua-5.1.4.orig/src/md5.c lua-5.1.4/src/md5.c
1089 --- lua-5.1.4.orig/src/md5.c 1970-01-01 01:00:00.000000000 +0100
1090 +++ lua-5.1.4/src/md5.c 2009-04-10 23:07:56.000000000 +0200
1093 + Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved.
1095 + This software is provided 'as-is', without any express or implied
1096 + warranty. In no event will the authors be held liable for any damages
1097 + arising from the use of this software.
1099 + Permission is granted to anyone to use this software for any purpose,
1100 + including commercial applications, and to alter it and redistribute it
1101 + freely, subject to the following restrictions:
1103 + 1. The origin of this software must not be misrepresented; you must not
1104 + claim that you wrote the original software. If you use this software
1105 + in a product, an acknowledgment in the product documentation would be
1106 + appreciated but is not required.
1107 + 2. Altered source versions must be plainly marked as such, and must not be
1108 + misrepresented as being the original software.
1109 + 3. This notice may not be removed or altered from any source distribution.
1115 +/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */
1117 + Independent implementation of MD5 (RFC 1321).
1119 + This code implements the MD5 Algorithm defined in RFC 1321, whose
1120 + text is available at
1121 + http://www.ietf.org/rfc/rfc1321.txt
1122 + The code is derived from the text of the RFC, including the test suite
1123 + (section A.5) but excluding the rest of Appendix A. It does not include
1124 + any code or documentation that is identified in the RFC as being
1127 + The original and principal author of md5.c is L. Peter Deutsch
1128 + <ghost@aladdin.com>. Other authors are noted in the change history
1129 + that follows (in reverse chronological order):
1131 + 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order
1132 + either statically or dynamically; added missing #include <string.h>
1134 + 2002-03-11 lpd Corrected argument list for main(), and added int return
1135 + type, in test program and T value program.
1136 + 2002-02-21 lpd Added missing #include <stdio.h> in test program.
1137 + 2000-07-03 lpd Patched to eliminate warnings about "constant is
1138 + unsigned in ANSI C, signed in traditional"; made test program
1140 + 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1141 + 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5).
1142 + 1999-05-03 lpd Original version.
1146 +#include <string.h>
1148 +#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */
1149 +#ifdef ARCH_IS_BIG_ENDIAN
1150 +# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1)
1152 +# define BYTE_ORDER 0
1155 +#define T_MASK ((md5_word_t)~0)
1156 +#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87)
1157 +#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9)
1158 +#define T3 0x242070db
1159 +#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111)
1160 +#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050)
1161 +#define T6 0x4787c62a
1162 +#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec)
1163 +#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe)
1164 +#define T9 0x698098d8
1165 +#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850)
1166 +#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e)
1167 +#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841)
1168 +#define T13 0x6b901122
1169 +#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c)
1170 +#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71)
1171 +#define T16 0x49b40821
1172 +#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d)
1173 +#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf)
1174 +#define T19 0x265e5a51
1175 +#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855)
1176 +#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2)
1177 +#define T22 0x02441453
1178 +#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e)
1179 +#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437)
1180 +#define T25 0x21e1cde6
1181 +#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829)
1182 +#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278)
1183 +#define T28 0x455a14ed
1184 +#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa)
1185 +#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07)
1186 +#define T31 0x676f02d9
1187 +#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375)
1188 +#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd)
1189 +#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e)
1190 +#define T35 0x6d9d6122
1191 +#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3)
1192 +#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb)
1193 +#define T38 0x4bdecfa9
1194 +#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f)
1195 +#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f)
1196 +#define T41 0x289b7ec6
1197 +#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805)
1198 +#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a)
1199 +#define T44 0x04881d05
1200 +#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6)
1201 +#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a)
1202 +#define T47 0x1fa27cf8
1203 +#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a)
1204 +#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb)
1205 +#define T50 0x432aff97
1206 +#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58)
1207 +#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6)
1208 +#define T53 0x655b59c3
1209 +#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d)
1210 +#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82)
1211 +#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e)
1212 +#define T57 0x6fa87e4f
1213 +#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f)
1214 +#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb)
1215 +#define T60 0x4e0811a1
1216 +#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d)
1217 +#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca)
1218 +#define T63 0x2ad7d2bb
1219 +#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e)
1223 +md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/)
1226 + a = pms->abcd[0], b = pms->abcd[1],
1227 + c = pms->abcd[2], d = pms->abcd[3];
1230 + /* Define storage only for big-endian CPUs. */
1233 + /* Define storage for little-endian or both types of CPUs. */
1234 + md5_word_t xbuf[16];
1235 + const md5_word_t *X;
1239 +#if BYTE_ORDER == 0
1241 + * Determine dynamically whether this is a big-endian or
1242 + * little-endian machine, since we can use a more efficient
1243 + * algorithm on the latter.
1245 + static const int w = 1;
1247 + if (*((const md5_byte_t *)&w)) /* dynamic little-endian */
1249 +#if BYTE_ORDER <= 0 /* little-endian */
1252 + * On little-endian machines, we can process properly aligned
1253 + * data without copying it.
1255 + if (!((data - (const md5_byte_t *)0) & 3)) {
1256 + /* data are properly aligned */
1257 + X = (const md5_word_t *)data;
1260 + memcpy(xbuf, data, 64);
1265 +#if BYTE_ORDER == 0
1266 + else /* dynamic big-endian */
1268 +#if BYTE_ORDER >= 0 /* big-endian */
1271 + * On big-endian machines, we must arrange the bytes in the
1274 + const md5_byte_t *xp = data;
1277 +# if BYTE_ORDER == 0
1278 + X = xbuf; /* (dynamic only) */
1280 +# define xbuf X /* (static only) */
1282 + for (i = 0; i < 16; ++i, xp += 4)
1283 + xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24);
1288 +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))
1291 + /* Let [abcd k s i] denote the operation
1292 + a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
1293 +#define F(x, y, z) (((x) & (y)) | (~(x) & (z)))
1294 +#define SET(a, b, c, d, k, s, Ti)\
1295 + t = a + F(b,c,d) + X[k] + Ti;\
1296 + a = ROTATE_LEFT(t, s) + b
1297 + /* Do the following 16 operations. */
1298 + SET(a, b, c, d, 0, 7, T1);
1299 + SET(d, a, b, c, 1, 12, T2);
1300 + SET(c, d, a, b, 2, 17, T3);
1301 + SET(b, c, d, a, 3, 22, T4);
1302 + SET(a, b, c, d, 4, 7, T5);
1303 + SET(d, a, b, c, 5, 12, T6);
1304 + SET(c, d, a, b, 6, 17, T7);
1305 + SET(b, c, d, a, 7, 22, T8);
1306 + SET(a, b, c, d, 8, 7, T9);
1307 + SET(d, a, b, c, 9, 12, T10);
1308 + SET(c, d, a, b, 10, 17, T11);
1309 + SET(b, c, d, a, 11, 22, T12);
1310 + SET(a, b, c, d, 12, 7, T13);
1311 + SET(d, a, b, c, 13, 12, T14);
1312 + SET(c, d, a, b, 14, 17, T15);
1313 + SET(b, c, d, a, 15, 22, T16);
1317 + /* Let [abcd k s i] denote the operation
1318 + a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */
1319 +#define G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
1320 +#define SET(a, b, c, d, k, s, Ti)\
1321 + t = a + G(b,c,d) + X[k] + Ti;\
1322 + a = ROTATE_LEFT(t, s) + b
1323 + /* Do the following 16 operations. */
1324 + SET(a, b, c, d, 1, 5, T17);
1325 + SET(d, a, b, c, 6, 9, T18);
1326 + SET(c, d, a, b, 11, 14, T19);
1327 + SET(b, c, d, a, 0, 20, T20);
1328 + SET(a, b, c, d, 5, 5, T21);
1329 + SET(d, a, b, c, 10, 9, T22);
1330 + SET(c, d, a, b, 15, 14, T23);
1331 + SET(b, c, d, a, 4, 20, T24);
1332 + SET(a, b, c, d, 9, 5, T25);
1333 + SET(d, a, b, c, 14, 9, T26);
1334 + SET(c, d, a, b, 3, 14, T27);
1335 + SET(b, c, d, a, 8, 20, T28);
1336 + SET(a, b, c, d, 13, 5, T29);
1337 + SET(d, a, b, c, 2, 9, T30);
1338 + SET(c, d, a, b, 7, 14, T31);
1339 + SET(b, c, d, a, 12, 20, T32);
1343 + /* Let [abcd k s t] denote the operation
1344 + a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */
1345 +#define H(x, y, z) ((x) ^ (y) ^ (z))
1346 +#define SET(a, b, c, d, k, s, Ti)\
1347 + t = a + H(b,c,d) + X[k] + Ti;\
1348 + a = ROTATE_LEFT(t, s) + b
1349 + /* Do the following 16 operations. */
1350 + SET(a, b, c, d, 5, 4, T33);
1351 + SET(d, a, b, c, 8, 11, T34);
1352 + SET(c, d, a, b, 11, 16, T35);
1353 + SET(b, c, d, a, 14, 23, T36);
1354 + SET(a, b, c, d, 1, 4, T37);
1355 + SET(d, a, b, c, 4, 11, T38);
1356 + SET(c, d, a, b, 7, 16, T39);
1357 + SET(b, c, d, a, 10, 23, T40);
1358 + SET(a, b, c, d, 13, 4, T41);
1359 + SET(d, a, b, c, 0, 11, T42);
1360 + SET(c, d, a, b, 3, 16, T43);
1361 + SET(b, c, d, a, 6, 23, T44);
1362 + SET(a, b, c, d, 9, 4, T45);
1363 + SET(d, a, b, c, 12, 11, T46);
1364 + SET(c, d, a, b, 15, 16, T47);
1365 + SET(b, c, d, a, 2, 23, T48);
1369 + /* Let [abcd k s t] denote the operation
1370 + a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */
1371 +#define I(x, y, z) ((y) ^ ((x) | ~(z)))
1372 +#define SET(a, b, c, d, k, s, Ti)\
1373 + t = a + I(b,c,d) + X[k] + Ti;\
1374 + a = ROTATE_LEFT(t, s) + b
1375 + /* Do the following 16 operations. */
1376 + SET(a, b, c, d, 0, 6, T49);
1377 + SET(d, a, b, c, 7, 10, T50);
1378 + SET(c, d, a, b, 14, 15, T51);
1379 + SET(b, c, d, a, 5, 21, T52);
1380 + SET(a, b, c, d, 12, 6, T53);
1381 + SET(d, a, b, c, 3, 10, T54);
1382 + SET(c, d, a, b, 10, 15, T55);
1383 + SET(b, c, d, a, 1, 21, T56);
1384 + SET(a, b, c, d, 8, 6, T57);
1385 + SET(d, a, b, c, 15, 10, T58);
1386 + SET(c, d, a, b, 6, 15, T59);
1387 + SET(b, c, d, a, 13, 21, T60);
1388 + SET(a, b, c, d, 4, 6, T61);
1389 + SET(d, a, b, c, 11, 10, T62);
1390 + SET(c, d, a, b, 2, 15, T63);
1391 + SET(b, c, d, a, 9, 21, T64);
1394 + /* Then perform the following additions. (That is increment each
1395 + of the four registers by the value it had before this block
1397 + pms->abcd[0] += a;
1398 + pms->abcd[1] += b;
1399 + pms->abcd[2] += c;
1400 + pms->abcd[3] += d;
1404 +md5_init(md5_state_t *pms)
1406 + pms->count[0] = pms->count[1] = 0;
1407 + pms->abcd[0] = 0x67452301;
1408 + pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476;
1409 + pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301;
1410 + pms->abcd[3] = 0x10325476;
1414 +md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
1416 + const md5_byte_t *p = data;
1417 + int left = nbytes;
1418 + int offset = (pms->count[0] >> 3) & 63;
1419 + md5_word_t nbits = (md5_word_t)(nbytes << 3);
1424 + /* Update the message length. */
1425 + pms->count[1] += nbytes >> 29;
1426 + pms->count[0] += nbits;
1427 + if (pms->count[0] < nbits)
1430 + /* Process an initial partial block. */
1432 + int copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
1434 + memcpy(pms->buf + offset, p, copy);
1435 + if (offset + copy < 64)
1439 + md5_process(pms, pms->buf);
1442 + /* Process full blocks. */
1443 + for (; left >= 64; p += 64, left -= 64)
1444 + md5_process(pms, p);
1446 + /* Process a final partial block. */
1448 + memcpy(pms->buf, p, left);
1452 +md5_finish(md5_state_t *pms, md5_byte_t digest[16])
1454 + static const md5_byte_t pad[64] = {
1455 + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1456 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1457 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1458 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1460 + md5_byte_t data[8];
1463 + /* Save the length before padding. */
1464 + for (i = 0; i < 8; ++i)
1465 + data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3));
1466 + /* Pad to 56 bytes mod 64. */
1467 + md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1);
1468 + /* Append the length. */
1469 + md5_append(pms, data, 8);
1470 + for (i = 0; i < 16; ++i)
1471 + digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3));
1473 diff -Nbur lua-5.1.4.orig/src/md5.h lua-5.1.4/src/md5.h
1474 --- lua-5.1.4.orig/src/md5.h 1970-01-01 01:00:00.000000000 +0100
1475 +++ lua-5.1.4/src/md5.h 2009-04-10 23:07:56.000000000 +0200
1478 + Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved.
1480 + This software is provided 'as-is', without any express or implied
1481 + warranty. In no event will the authors be held liable for any damages
1482 + arising from the use of this software.
1484 + Permission is granted to anyone to use this software for any purpose,
1485 + including commercial applications, and to alter it and redistribute it
1486 + freely, subject to the following restrictions:
1488 + 1. The origin of this software must not be misrepresented; you must not
1489 + claim that you wrote the original software. If you use this software
1490 + in a product, an acknowledgment in the product documentation would be
1491 + appreciated but is not required.
1492 + 2. Altered source versions must be plainly marked as such, and must not be
1493 + misrepresented as being the original software.
1494 + 3. This notice may not be removed or altered from any source distribution.
1500 +/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */
1502 + Independent implementation of MD5 (RFC 1321).
1504 + This code implements the MD5 Algorithm defined in RFC 1321, whose
1505 + text is available at
1506 + http://www.ietf.org/rfc/rfc1321.txt
1507 + The code is derived from the text of the RFC, including the test suite
1508 + (section A.5) but excluding the rest of Appendix A. It does not include
1509 + any code or documentation that is identified in the RFC as being
1512 + The original and principal author of md5.h is L. Peter Deutsch
1513 + <ghost@aladdin.com>. Other authors are noted in the change history
1514 + that follows (in reverse chronological order):
1516 + 2002-04-13 lpd Removed support for non-ANSI compilers; removed
1517 + references to Ghostscript; clarified derivation from RFC 1321;
1518 + now handles byte order either statically or dynamically.
1519 + 1999-11-04 lpd Edited comments slightly for automatic TOC extraction.
1520 + 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5);
1521 + added conditionalization for C++ compilation from Martin
1522 + Purschke <purschke@bnl.gov>.
1523 + 1999-05-03 lpd Original version.
1526 +#ifndef md5_INCLUDED
1527 +# define md5_INCLUDED
1530 + * This package supports both compile-time and run-time determination of CPU
1531 + * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be
1532 + * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is
1533 + * defined as non-zero, the code will be compiled to run only on big-endian
1534 + * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to
1535 + * run on either big- or little-endian CPUs, but will run slightly less
1536 + * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined.
1539 +typedef unsigned char md5_byte_t; /* 8-bit byte */
1540 +typedef unsigned int md5_word_t; /* 32-bit word */
1542 +/* Define the state of the MD5 Algorithm. */
1543 +typedef struct md5_state_s {
1544 + md5_word_t count[2]; /* message length in bits, lsw first */
1545 + md5_word_t abcd[4]; /* digest buffer */
1546 + md5_byte_t buf[64]; /* accumulate block */
1554 +/* Initialize the algorithm. */
1555 +void md5_init(md5_state_t *pms);
1557 +/* Append a string to the message. */
1558 +void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes);
1560 +/* Finish the message and return the digest. */
1561 +void md5_finish(md5_state_t *pms, md5_byte_t digest[16]);
1564 +} /* end extern "C" */
1567 +#endif /* md5_INCLUDED */