source: trunk/base/src/pextlib1.0/rmd160cmd.c @ 16350

Last change on this file since 16350 was 16350, checked in by landonf (Landon Fuller), 15 years ago

Fix bogus preprocessor usage

  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/*
2 * rmd160cmd.c
3 * $Id: rmd160cmd.c,v 1.2 2006/02/12 06:04:46 landonf Exp $
4 *
5 * Copyright (c) 2005 Paul Guyot <pguyot@kallisys.net>.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
17 *    may be used to endorse or promote products derived from this software
18 *    without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#if HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#include <tcl.h>
38
39#if HAVE_STRING_H
40#include <string.h>
41#endif
42
43#if !defined(HAVE_LIBMD)
44
45/* We do not have libmd.
46 * let's use our own version of rmd160* libraries.
47 */
48#include <stdio.h>
49#include <fcntl.h>
50#include <stdlib.h>
51#include <unistd.h>
52#include <errno.h>
53
54#include <sys/types.h>
55
56#include "rmd160.h"
57#include "rmd160.c"
58#define RIPEMD160_DIGEST_LENGTH 20
59#include "md_wrappers.h"
60CHECKSUMEnd(RMD160, RMD160_CTX, RIPEMD160_DIGEST_LENGTH)
61CHECKSUMFile(RMD160, RMD160_CTX)
62CHECKSUMData(RMD160, RMD160_CTX)
63
64#elif defined(HAVE_LIBMD)
65#include <sys/types.h>
66#include <ripemd.h>
67#define RMD160File(x, y) RIPEMD160_File(x, y)
68#else
69#error libcrypto or libmd are required
70#endif
71
72int RMD160Cmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
73{
74        char *file, *action;
75        char buf[2*RIPEMD160_DIGEST_LENGTH + 1];
76        const char usage_message[] = "Usage: rmd160 file";
77        const char error_message[] = "Could not open file: ";
78        Tcl_Obj *tcl_result;
79
80        if (objc != 3) {
81                Tcl_WrongNumArgs(interp, 1, objv, "action ?file?");
82                return TCL_ERROR;
83        }
84
85        /*
86         * Only the 'file' action is currently supported
87         */
88        action = Tcl_GetString(objv[1]);
89        if (strcmp(action, "file") != 0) {
90                tcl_result = Tcl_NewStringObj(usage_message, sizeof(usage_message) - 1);
91                Tcl_SetObjResult(interp, tcl_result);
92                return TCL_ERROR;
93        }
94        file = Tcl_GetString(objv[2]);
95
96        if (!RMD160File(file, buf)) {
97                tcl_result = Tcl_NewStringObj(error_message, sizeof(error_message) - 1);
98                Tcl_AppendObjToObj(tcl_result, Tcl_NewStringObj(file, -1));
99                Tcl_SetObjResult(interp, tcl_result);
100                return TCL_ERROR;
101        }
102        tcl_result = Tcl_NewStringObj(buf, sizeof(buf) - 1);
103        Tcl_SetObjResult(interp, tcl_result);
104        return TCL_OK;
105}
Note: See TracBrowser for help on using the repository browser.