-
Notifications
You must be signed in to change notification settings - Fork 2
/
sommelier-util.cc
32 lines (27 loc) · 1.07 KB
/
sommelier-util.cc
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
// Copyright 2021 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sommelier-util.h" // NOLINT(build/include_directory)
#include <stdarg.h>
#include <stdio.h>
// Performs an asprintf operation and checks the result for validity and calls
// abort() if there's a failure. Returns a newly allocated string rather than
// taking a double pointer argument like asprintf.
__attribute__((__format__(__printf__, 1, 0))) char* sl_xasprintf(
const char* fmt, ...) {
char* str;
va_list args;
va_start(args, fmt);
int rv = vasprintf(&str, fmt, args);
assert(rv >= 0);
UNUSED(rv);
va_end(args);
return str;
}
#define DEFAULT_DELETER(TypeName, DeleteFunction) \
namespace std { \
void default_delete<TypeName>::operator()(TypeName* ptr) { \
DeleteFunction(ptr); \
} \
}
DEFAULT_DELETER(struct wl_event_source, wl_event_source_remove);