File: error.c

package info (click to toggle)
linux-minidisc 0.9.13-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,096 kB
  • ctags: 1,530
  • sloc: ansic: 6,345; cpp: 2,569; python: 2,451; perl: 866; sh: 22; makefile: 8
file content (61 lines) | stat: -rw-r--r-- 1,940 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * error.c
 *
 * This file is part of libnetmd, a library for accessing Sony NetMD devices.
 *
 * Copyright (C) 2011 Alexander Sulfrian
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#include "error.h"

struct error_description {
    netmd_error error;
    const char* const description;
};

static struct error_description const descriptions[] = {
    {NETMD_NO_ERROR, "No error"},
    {NETMD_NOT_IMPLEMENTED, "Not implemented"},

    {NETMD_USB_OPEN_ERROR, "Error while opening the USB device"},
    {NETMD_USB_ERROR, "Generic USB error"},

    {NETMD_RESPONSE_TO_SHORT, "Response from device is shorter than expected."},
    {NETMD_RESPONSE_NOT_EXPECTED, "Response from device does not match with the expected result."},

    {NETMD_DES_ERROR, "Error during des caluclation."}
};

static char const unknown_error[] = "Unknown Error";

const char* netmd_strerror(netmd_error error)
{
    unsigned int i = 0;
    unsigned int elements;

    /* calculate the number of elements in the array */
    elements = sizeof(descriptions) / sizeof(*descriptions);

    for (i = 0; i < elements; i++) {
        if (descriptions[i].error == error) {
            return descriptions[i].description;
        }
    }

    return unknown_error;
}