aboutsummaryrefslogtreecommitdiff
path: root/libssh/error.c
blob: 78a7ea12b1d77f85c111abc5162b4f63ea6418ba (plain)
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
/* error.c */
/* it does contain error processing functions */
/*
Copyright 2003,04 Aris Adamantiadis

This file is part of the SSH Library

The SSH 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.

The SSH 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 the SSH Library; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */

#include <stdio.h>
#include <stdarg.h>
#include "libssh/priv.h"

static int verbosity;

/* ssh_set_error registers an error with a description. the error code is the class of error, and description is obvious.*/
void ssh_set_error(void *error,int code,char *descr,...){
    struct error_struct *err= error;
    va_list va;
    va_start(va,descr);
    vsnprintf(err->error_buffer,ERROR_BUFFERLEN,descr,va);
    va_end(va);
    err->error_code=code;
}

char *ssh_get_error(void *error){
    struct error_struct *err=error;
    return err->error_buffer;
}

int ssh_get_error_code(void *error){
    struct error_struct *err=error;
    return err->error_code;
}

void ssh_say(int priority, char *format,...){
    va_list va;
    va_start(va,format);
    if(priority <= verbosity)
        vfprintf(stderr,format,va);
    va_end(va);
}

void ssh_set_verbosity(int num){
    verbosity=num;
}