APUE Learning Example Source Code
guowenxue
2020-04-13 808fdc2c3745074a941fc73c9e6233d8e41cfdc0
Add library and makefile sample code
7 files deleted
5 files added
392 ■■■■ changed files
ch7_library/lib/crypto.h 28 ●●●●● patch | view | raw | blame | history
ch7_library/makefile 18 ●●●●● patch | view | raw | blame | history
ch7_library/src/crypto.c 48 ●●●●● patch | view | raw | blame | history
ch7_library/src/crypto.h 28 ●●●●● patch | view | raw | blame | history
ch7_library/src/makefile 32 ●●●●● patch | view | raw | blame | history
ch7_library/test/main.c 43 ●●●●● patch | view | raw | blame | history
ch7_library/test/makefile 18 ●●●●● patch | view | raw | blame | history
lib_makefile/encrypto/encrypto.c 66 ●●●●● patch | view | raw | blame | history
lib_makefile/encrypto/encrypto.h 23 ●●●●● patch | view | raw | blame | history
lib_makefile/encrypto/makefile 22 ●●●●● patch | view | raw | blame | history
lib_makefile/main.c 32 ●●●●● patch | view | raw | blame | history
lib_makefile/makefile 34 ●●●●● patch | view | raw | blame | history
ch7_library/lib/crypto.h
File was deleted
ch7_library/makefile
File was deleted
ch7_library/src/crypto.c
File was deleted
ch7_library/src/crypto.h
File was deleted
ch7_library/src/makefile
File was deleted
ch7_library/test/main.c
File was deleted
ch7_library/test/makefile
File was deleted
lib_makefile/encrypto/encrypto.c
New file
@@ -0,0 +1,66 @@
/*********************************************************************************
 *      Copyright:  (C) 2020 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  encrypto.c
 *    Description:  This file
 *
 *        Version:  1.0.0(2020年04月04日)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "2020年04月04日 21时02分36秒"
 *
 ********************************************************************************/
#include <stdio.h>
#include <string.h>
#include "encrypto.h"
int       g_var = 0;
static int test(void)
{
    return 0;
}
int encrypto(char *str, char *ciphertxt, int size)
{
    int i;
    test();
    if(!str || !ciphertxt || size<strlen(str))
    {
        printf("%s:%d %s(): Invalid input arguments\n", __FILE__, __LINE__, __FUNCTION__);
        return -1;
    }
    for(i=0; i<strlen(str); i++)
    {
        ciphertxt[i]=str[i]+1;
    }
    g_var ++;
    return 0;
}
int decrypto(char *ciphertxt, char *text, int size)
{
    int i;
    if( !ciphertxt || !text || size<strlen(ciphertxt) )
    {
        printf("%s:%d %s(): Invalid input arguments\n", __FILE__, __LINE__, __FUNCTION__);
        return -1;
    }
    for(i=0; i<strlen(ciphertxt); i++)
    {
        text[i]=ciphertxt[i]-1;
    }
    return 0;
}
lib_makefile/encrypto/encrypto.h
New file
@@ -0,0 +1,23 @@
/********************************************************************************
 *      Copyright:  (C) 2020 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  encrypto.h
 *    Description:  This head file
 *
 *        Version:  1.0.0(2020年04月04日)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "2020年04月04日 21时13分05秒"
 *
 ********************************************************************************/
#ifndef  _ENCRYPTO_H_
#define  _ENCRYPTO_H_
extern int       g_var ;
int encrypto(char *str, char *ciphertxt, int size);
int decrypto(char *ciphertxt, char *text, int size);
#endif   /* ----- #ifndef _ENCRYPTO_H_  ----- */
lib_makefile/encrypto/makefile
New file
@@ -0,0 +1,22 @@
LIBNAME=libencrypto
CC=${CROSSTOOL}gcc
LD=${CROSSTOOL}ld
AS=${CROSSTOOL}as
AR=${CROSSTOOL}ar
all: liba
    @rm -f *.o
libso:
    ${CC} -fPIC -shared *.c -o ${LIBNAME}.so
liba:
    ${CC} -c *.c
    ${AR} -rcs ${LIBNAME}.a *.o
clean:
    rm -f ${LIBNAME}.*
distclean: clean
    rm -f *.o
lib_makefile/main.c
New file
@@ -0,0 +1,32 @@
/*********************************************************************************
 *      Copyright:  (C) 2020 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  main.c
 *    Description:  This file
 *
 *        Version:  1.0.0(2020年04月04日)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "2020年04月04日 20时57分10秒"
 *
 ********************************************************************************/
#include <stdio.h>
#include "encrypto.h"
int main (int argc, char *argv[])
{
    char    *str="hello world";
    char     ciphertxt[128];
    char     text[128];
    encrypto(str, ciphertxt, 128);
    printf("cipher text: %s\r\n", ciphertxt);
    decrypto(ciphertxt, text, 128);
    printf("text: %s\r\n", text);
    return 0;
}
lib_makefile/makefile
New file
@@ -0,0 +1,34 @@
APP_NAME=test
CROSSTOOL?=/opt/rpi/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-
CC=${CROSSTOOL}gcc
LD=${CROSSTOOL}ld
AS=${CROSSTOOL}as
AR=${CROSSTOOL}ar
# Compile flags
CFLAGS=-Wall -Werror
CFLAGS+=-Iencrypto
# Linker flags
LDFLAGS=-Lencrypto -lencrypto
all: banner libencrypto
    ${CC} ${CFLAGS} main.c -o ${APP_NAME} ${LDFLAGS}
banner:
    @echo "Start to compile ${SRC} by ${CC}"
libencrypto:
    @make CROSSTOOL=${CROSSTOOL} -C encrypto
clean:
    @make clean -C encrypto
    rm -f ${APP_NAME}
distclean: clean
    @make distclean -C encrypto
    rm -f *.o