#include "compositor.h"
#include "../shared/os-compatibility.h"
#include "../shared/helpers.h"
+#include "../shared/string-helpers.h"
#include "git-version.h"
#include "version.h"
#include "weston.h"
char *modules = NULL;
char *option_modules = NULL;
char *log = NULL;
- char *server_socket = NULL, *end;
+ char *server_socket = NULL;
int32_t idle_time = -1;
int32_t help = 0;
char *socket_name = NULL;
server_socket = getenv("WAYLAND_SERVER_SOCKET");
if (server_socket) {
weston_log("Running with single client\n");
- errno = 0;
- fd = strtol(server_socket, &end, 10);
- if (errno != 0 || end == server_socket || *end != '\0')
+ if (!safe_strtoint(server_socket, &fd))
fd = -1;
} else {
fd = -1;
#include "config.h"
-#include <errno.h>
#include <stdlib.h>
#include <systemd/sd-daemon.h>
#include <sys/socket.h>
#include <wayland-server.h>
+
#include "shared/helpers.h"
+#include "shared/string-helpers.h"
#include "shared/zalloc.h"
#include "compositor.h"
module_init(struct weston_compositor *compositor,
int *argc, char *argv[])
{
- char *tail;
char *watchdog_time_env;
struct wl_event_loop *loop;
long watchdog_time_conv;
* by systemd to transfer 'WatchdogSec' watchdog timeout
* setting from service file.*/
watchdog_time_env = getenv("WATCHDOG_USEC");
-
if (!watchdog_time_env)
return 0;
- errno = 0;
- watchdog_time_conv = strtol(watchdog_time_env, &tail, 10);
- if (errno != 0 || tail == watchdog_time_env || *tail != '\0')
+ if (!safe_strtoint(watchdog_time_env, &watchdog_time_conv))
return 0;
/* Convert 'WATCHDOG_USEC' to milliseconds and notify
#include "presentation-time-server-protocol.h"
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
+#include "shared/string-helpers.h"
#include "shared/timespec-util.h"
#include "git-version.h"
#include "version.h"
WL_EXPORT int
weston_environment_get_fd(const char *env)
{
- char *e, *end;
+ char *e;
int fd, flags;
e = getenv(env);
- if (!e)
- return -1;
- errno = 0;
- fd = strtol(e, &end, 10);
- if (errno != 0 || end == e || *end != '\0')
+ if (!e || !safe_strtoint(e, &fd))
return -1;
flags = fcntl(fd, F_GETFD);
#include <string.h>
#include <errno.h>
+#include "shared/string-helpers.h"
+
static long backlight_get(struct backlight *backlight, char *node)
{
char buffer[100];
char *path;
- char *end;
- int fd;
- long value, ret;
+ int fd, value;
+ long ret;
if (asprintf(&path, "%s/%s", backlight->path, node) < 0)
return -ENOMEM;
goto out;
}
- errno = 0;
- value = strtol(buffer, &end, 10);
- if (errno != 0 || end == buffer || *end != '\0') {
+ if (!safe_strtoint(buffer, &value)) {
ret = -1;
goto out;
}
#include <wayland-util.h>
#include "config-parser.h"
#include "helpers.h"
+#include "string-helpers.h"
struct weston_config_entry {
char *key;
int32_t *value, int32_t default_value)
{
struct weston_config_entry *entry;
- char *end;
entry = config_section_get_entry(section, key);
if (entry == NULL) {
return -1;
}
- errno = 0;
- *value = strtol(entry->value, &end, 10);
- if (errno != 0 || end == entry->value || *end != '\0') {
+ if (!safe_strtoint(entry->value, value)) {
*value = default_value;
- errno = EINVAL;
return -1;
}
#include <errno.h>
#include "config-parser.h"
+#include "string-helpers.h"
static int
handle_option(const struct weston_option *option, char *value)
switch (option->type) {
case WESTON_OPTION_INTEGER:
- errno = 0;
- * (int32_t *) option->data = strtol(value, &p, 10);
- if (errno != 0 || p == value || *p != '\0')
+ if (!safe_strtoint(value, option->data))
return 0;
return 1;
case WESTON_OPTION_UNSIGNED_INTEGER:
#include "xwayland.h"
#include "xwayland-api.h"
#include "shared/helpers.h"
+#include "shared/string-helpers.h"
#include "compositor/weston.h"
static int
static int
create_lockfile(int display, char *lockfile, size_t lsize)
{
- char pid[16], *end;
+ char pid[16];
int fd, size;
pid_t other;
return -1;
}
- errno = 0;
- other = strtol(pid, &end, 10);
- if (errno != 0 || end == pid || *end != '\0') {
+ if (!safe_strtoint(pid, &other)) {
weston_log("can't parse lock file %s\n",
lockfile);
close(fd);