diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-04-07 18:33:12 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-04-07 18:33:12 +0200 |
commit | f822e622bb4a112e38dc74bf11f1b3a1e6e066f2 (patch) | |
tree | 384916009aa79f9c80d60d9f874a028641ba8b62 | |
parent | fix warnings (diff) | |
download | libpassphrase-1396888621.tar.gz libpassphrase-1396888621.tar.bz2 libpassphrase-1396888621.tar.xz |
add test + fix example in info manual1396888621
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | Makefile | 19 | ||||
-rw-r--r-- | info/libpassphrase.texinfo | 4 | ||||
-rw-r--r-- | src/passphrase.h | 4 | ||||
-rw-r--r-- | src/test.c | 69 | ||||
-rw-r--r-- | src/test.h | 30 |
5 files changed, 117 insertions, 9 deletions
@@ -57,24 +57,24 @@ STD = gnu99 # C preprocessor flags CPPFLAGS_ = $(foreach D, $(OPTIONS), -D'$(D)=1') $(CPPFLAGS) # C compiling flags -CFLAGS_ = -std=$(STD) $(WARN) -fPIC $(CFLAGS) +_fPIC = -fPIC +CFLAGS_ = -std=$(STD) $(WARN) $(_fPIC) $(CFLAGS) # Linking flags -LDFLAGS_ = -shared $(LDFLAGS) +_shared = -shared +LDFLAGS_ = $(_shared) $(LDFLAGS) # Flags to use when compiling and assembling CC_FLAGS = $(CPPFLAGS_) $(CFLAGS_) $(OPTIMISE) # Flags to use when linking LD_FLAGS = $(LDFLAGS_) $(CFLAGS_) $(OPTIMISE) -SRC = passphrase -OBJ = $(foreach S, $(SRC), obj/$(S).o) .PHONY: default default: libpassphrase info .PHONY: all -all: libpassphrase doc +all: libpassphrase test doc .PHONY: doc doc: info pdf ps dvi @@ -82,7 +82,14 @@ doc: info pdf ps dvi .PHONY: libpassphrase libpassphrase: bin/libpassphrase.so -bin/libpassphrase.so: $(OBJ) +.PHONY: test +test: bin/test + +bin/libpassphrase.so: obj/passphrase.o + @mkdir -p bin + $(CC) $(LD_FLAGS) -o "$@" $^ + +bin/test: obj/passphrase.o obj/test.o @mkdir -p bin $(CC) $(LD_FLAGS) -o "$@" $^ diff --git a/info/libpassphrase.texinfo b/info/libpassphrase.texinfo index 5136d20..7eaf9a5 100644 --- a/info/libpassphrase.texinfo +++ b/info/libpassphrase.texinfo @@ -149,11 +149,13 @@ been disabled. @example #include <passphrase.h> /* For libpassphrase */ #include <stdio.h> /* For output */ +#include <stdlib.h> /* For free */ int main(int argc, char** argv) @{ /* Variables for the passphrase */ - char* passphrase, passphrase_; + char* passphrase; + char* passphrase_; /* Hide the passphrase */ passphrase_disable_echo(); diff --git a/src/passphrase.h b/src/passphrase.h index d6ecdce..932b6e5 100644 --- a/src/passphrase.h +++ b/src/passphrase.h @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __PASSPHRASE_H__ -#define __PASSPHRASE_H__ +#ifndef PASSPHRASE_H +#define PASSPHRASE_H /** diff --git a/src/test.c b/src/test.c new file mode 100644 index 0000000..1416be3 --- /dev/null +++ b/src/test.c @@ -0,0 +1,69 @@ +/** + * libpassphrase – Personalisable library for TTY passphrase reading + * + * Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "test.h" + + +/** + * Main test function + * + * @param argc Number of elements in `argv` + * @param argv Command line arguments + * @return Zero on success + */ +int main(int argc, char** argv) +{ + /* Variables for the passphrase */ + char* passphrase; + char* passphrase_; + + /* Hide the passphrase */ + passphrase_disable_echo(); + + /* Do things needed before reading the passphrase */ + printf("Passphrase: "); + fflush(stdout); + + /* Read the passphrase */ + passphrase = passphrase_read(); + if (passphrase == NULL) + { + /* Something went wrong, print what and exit */ + perror(*argv); + return 1; + } + + /* Use the passphrase */ + printf("You entered: %s\n", passphrase); + + /* Wipe and free the passphrase */ + passphrase_ = passphrase; + while (*passphrase) + *passphrase++ = 0; + free(passphrase_); + + /* Stop hiding user input */ + passphrase_reenable_echo(); + + /* End of program */ + return 0; + + /* `argc` was never used */ + (void) argc; +} + diff --git a/src/test.h b/src/test.h new file mode 100644 index 0000000..12ddb4a --- /dev/null +++ b/src/test.h @@ -0,0 +1,30 @@ +/** + * libpassphrase – Personalisable library for TTY passphrase reading + * + * Copyright © 2013, 2014 Mattias Andrée (maandree@member.fsf.org) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef TEST_H +#define TEST_H + + +#include <stdio.h> +#include <stdlib.h> + +#include "passphrase.h" + + +#endif + |