From 5f50148c208a764fa3c477436050356b2e24c121 Mon Sep 17 00:00:00 2001 From: Date: Wed, 19 Sep 2007 11:30:17 +0200 Subject: [PATCH] Updates to all applications. New memcp and have fixed minor issue with memcat. --- src/Makefile.am | 6 +++- src/memcat.c | 4 +-- src/memcp.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 src/memcp.c diff --git a/src/Makefile.am b/src/Makefile.am index 47507bea..fc47cc49 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,10 @@ INCLUDES = -I$(top_builddir)/include LDADDS = ../lib/libmemcached.la -bin_PROGRAMS = memcat +bin_PROGRAMS = memcat memcp + memcat_SOURCES = memcat.c memcat_LDADD = $(LDADDS) + +memcp_SOURCES = memcp.c +memcp_LDADD = $(LDADDS) diff --git a/src/memcat.c b/src/memcat.c index ba20f3e7..0fc38d6c 100644 --- a/src/memcat.c +++ b/src/memcat.c @@ -15,9 +15,9 @@ int main(int argc, char *argv[]) memc= memcached_init(NULL); - for (x= 1; x <= argc; x++) + for (x= 1; x < argc; x++) { - string= memcached_get(memc, argv[1], strlen(argv[1]), + string= memcached_get(memc, argv[x], strlen(argv[x]), &string_length, &flags, &rc); if (string) { diff --git a/src/memcp.c b/src/memcp.c new file mode 100644 index 00000000..3430ab54 --- /dev/null +++ b/src/memcp.c @@ -0,0 +1,92 @@ +#include +#include +#include +#include +#include +#include + +#include + +int main(int argc, char *argv[]) +{ + memcached_st *memc; + char *string; + unsigned int x; + size_t string_length; + uint16_t flags; + memcached_return rc; + + if (argc < 3) + return 0; + + memc= memcached_init(NULL); + + /* Get the server name */ + { + char *ptr; + char *hostname; + size_t hostname_length; + unsigned int port; + + ptr= index(argv[argc-1], ':'); + + if (ptr) + { + hostname_length= ptr - argv[argc-1]; + hostname= (char *)malloc(hostname_length+1); + memset(hostname, 0, hostname_length+1); + memcpy(hostname, argv[argc-1], hostname_length); + + ptr++; + + port= strtol(ptr, (char **)NULL, 10); + + memcached_server_add(memc, hostname, port); + free(hostname); + } + else + { + memcached_server_add(memc, argv[argc -1], 0); + } + } + + for (x= 1; x < argc-1; x++) + { + char *mptr; + struct stat sbuf; + int fd; + char *ptr; + + fd= open(argv[x], O_RDONLY); + + if (fd == -1) + { + fprintf(stderr, "Failed opening %s\n", argv[x]); + exit(1); + } + + (void)fstat(fd, &sbuf); + mptr= mmap(NULL, sbuf.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + + ptr= rindex(argv[x], '/'); + if (ptr) + { + ptr++; + } + else + { + ptr= argv[x]; + } + + rc= memcached_set(memc, ptr, strlen(ptr), + mptr, sbuf.st_size, + (time_t)0, (uint16_t)0); + + munmap(mptr, sbuf.st_size); + close(fd); + } + + memcached_deinit(memc); + + return 0; +}; -- 2.30.2