bus-error.c revision eb01ba5de14859d7a94835ab9299de40132d549a
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
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.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include "util.h"
#include "sd-bus.h"
#include "bus-error.h"
bool bus_error_is_dirty(sd_bus_error *e) {
if (!e)
return 0;
}
void sd_bus_error_free(sd_bus_error *e) {
if (!e)
return;
if (e->need_free) {
}
e->need_free = false;
}
char *n, *m = NULL;
int r;
if (!e)
return 0;
if (bus_error_is_dirty(e))
return -EINVAL;
if (!name)
return -EINVAL;
if (!n)
return -ENOMEM;
if (format) {
if (r < 0) {
free(n);
return -ENOMEM;
}
}
e->name = n;
e->message = m;
e->need_free = true;
return 0;
}
char *x, *y = NULL;
if (!dest)
return 0;
if (bus_error_is_dirty(dest))
return -EINVAL;
if (!sd_bus_error_is_set(e))
return 0;
if (!x)
return -ENOMEM;
if (e->message) {
if (!y) {
free(x);
return -ENOMEM;
}
}
return 0;
}
if (!e)
return;
if (bus_error_is_dirty(e))
return;
e->need_free = false;
}
int sd_bus_error_is_set(const sd_bus_error *e) {
if (!e)
return 0;
return !!e->name;
}
if (!e)
return 0;
}
int bus_error_to_errno(const sd_bus_error* e) {
/* Better replce this with a gperf table */
if (!e)
return -EIO;
if (!e->name)
return -EIO;
return -ENOMEM;
return -EPERM;
return -EINVAL;
return -ESRCH;
return -ENOENT;
return -EEXIST;
return -ETIMEDOUT;
return -EIO;
return -ECONNRESET;
return -ENOTSUP;
return -EIO;
}
if (!e)
return error;
switch (error) {
case -ENOMEM:
break;
case -EPERM:
case -EACCES:
break;
case -EINVAL:
break;
case -ESRCH:
break;
case -ENOENT:
break;
case -EEXIST:
break;
case -ETIMEDOUT:
case -ETIME:
break;
case -EIO:
break;
case -ENETRESET:
case -ECONNABORTED:
case -ECONNRESET:
break;
case -ENOTSUP:
break;
}
return error;
}
if (e && e->message)
return e->message;
}