INCLUDES = -I$(top_builddir)/include\r
LDADDS = ../lib/libmemcached.la\r
\r
-bin_PROGRAMS = memcat\r
+bin_PROGRAMS = memcat memcp\r
+\r
memcat_SOURCES = memcat.c\r
memcat_LDADD = $(LDADDS)\r
+\r
+memcp_SOURCES = memcp.c\r
+memcp_LDADD = $(LDADDS)\r
\r
memc= memcached_init(NULL);\r
\r
- for (x= 1; x <= argc; x++)\r
+ for (x= 1; x < argc; x++)\r
{\r
- string= memcached_get(memc, argv[1], strlen(argv[1]),\r
+ string= memcached_get(memc, argv[x], strlen(argv[x]),\r
&string_length, &flags, &rc);\r
if (string)\r
{\r
--- /dev/null
+#include <stdio.h>\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+#include <sys/types.h>\r
+#include <sys/mman.h>\r
+#include <fcntl.h>\r
+\r
+#include <memcached.h>\r
+\r
+int main(int argc, char *argv[])\r
+{\r
+ memcached_st *memc;\r
+ char *string;\r
+ unsigned int x;\r
+ size_t string_length;\r
+ uint16_t flags;\r
+ memcached_return rc;\r
+\r
+ if (argc < 3)\r
+ return 0;\r
+\r
+ memc= memcached_init(NULL);\r
+\r
+ /* Get the server name */\r
+ {\r
+ char *ptr;\r
+ char *hostname;\r
+ size_t hostname_length;\r
+ unsigned int port;\r
+\r
+ ptr= index(argv[argc-1], ':');\r
+\r
+ if (ptr)\r
+ {\r
+ hostname_length= ptr - argv[argc-1];\r
+ hostname= (char *)malloc(hostname_length+1);\r
+ memset(hostname, 0, hostname_length+1);\r
+ memcpy(hostname, argv[argc-1], hostname_length);\r
+\r
+ ptr++;\r
+\r
+ port= strtol(ptr, (char **)NULL, 10);\r
+\r
+ memcached_server_add(memc, hostname, port);\r
+ free(hostname);\r
+ }\r
+ else\r
+ {\r
+ memcached_server_add(memc, argv[argc -1], 0);\r
+ }\r
+ }\r
+\r
+ for (x= 1; x < argc-1; x++)\r
+ {\r
+ char *mptr;\r
+ struct stat sbuf;\r
+ int fd;\r
+ char *ptr;\r
+\r
+ fd= open(argv[x], O_RDONLY);\r
+\r
+ if (fd == -1)\r
+ {\r
+ fprintf(stderr, "Failed opening %s\n", argv[x]);\r
+ exit(1);\r
+ }\r
+\r
+ (void)fstat(fd, &sbuf);\r
+ mptr= mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0);\r
+\r
+ ptr= rindex(argv[x], '/');\r
+ if (ptr)\r
+ {\r
+ ptr++;\r
+ }\r
+ else\r
+ {\r
+ ptr= argv[x];\r
+ }\r
+ \r
+ rc= memcached_set(memc, ptr, strlen(ptr),\r
+ mptr, sbuf.st_size,\r
+ (time_t)0, (uint16_t)0);\r
+\r
+ munmap(mptr, sbuf.st_size);\r
+ close(fd);\r
+ }\r
+\r
+ memcached_deinit(memc);\r
+\r
+ return 0;\r
+};\r