*/
#define REQUIRE_ROOT_OR_RESOLVE_DEVICE(path,fail_stmt) \
do { \
- if (strncmp ((path), "/dev/", 5) == 0) \
+ if (STREQLEN ((path), "/dev/", 5)) \
RESOLVE_DEVICE ((path), fail_stmt); \
else { \
NEED_ROOT (fail_stmt); \
struct dirent *d = readdir(dir);
if(NULL == d) break;
- if (strncmp (d->d_name, "sd", 2) == 0 ||
- strncmp (d->d_name, "hd", 2) == 0 ||
- strncmp (d->d_name, "vd", 2) == 0 ||
- strncmp (d->d_name, "sr", 2) == 0) {
+ if (STREQLEN (d->d_name, "sd", 2) ||
+ STREQLEN (d->d_name, "hd", 2) ||
+ STREQLEN (d->d_name, "vd", 2) ||
+ STREQLEN (d->d_name, "sr", 2)) {
char dev_path[256];
snprintf (dev_path, sizeof dev_path, "/dev/%s", d->d_name);
errno = 0;
struct dirent *d;
while ((d = readdir (dir)) != NULL) {
- if (strncmp (d->d_name, device, strlen (device)) == 0) {
+ if (STREQLEN (d->d_name, device, strlen (device))) {
char part[256];
snprintf (part, sizeof part, "/dev/%s", d->d_name);
p = out;
/* Discard the first line if it contains "tune2fs ...". */
- if (strncmp (p, "tune2fs ", 8) == 0) {
+ if (STREQLEN (p, "tune2fs ", 8)) {
p = strchr (p, '\n');
if (p) p++;
else {
char *buf;
int len;
- if (strncmp (path, "/dev/", 5) == 0)
+ if (STREQLEN (path, "/dev/", 5))
buf = (char *) path;
else {
buf = sysroot_path (path);
/* Connect to vmchannel. */
int sock = -1;
- if (strncmp (vmchannel, "tcp:", 4) == 0) {
+ if (STREQLEN (vmchannel, "tcp:", 4)) {
/* Resolve the hostname. */
struct addrinfo *res, *rr;
struct addrinfo hints;
char *buf;
int is_dev;
- is_dev = strncmp (pathordevice, "/dev/", 5) == 0;
+ is_dev = STREQLEN (pathordevice, "/dev/", 5);
buf = is_dev ? strdup (pathordevice)
: sysroot_path (pathordevice);
if (buf == NULL) {
{
int err, fd, r, is_dev;
- is_dev = strncmp (filename, "/dev/", 5) == 0;
+ is_dev = STREQLEN (filename, "/dev/", 5);
if (!is_dev) {
if (!root_mounted || filename[0] != '/') {
cancel_receive ();
int fd, r, is_dev;
char buf[GUESTFS_MAX_CHUNK_SIZE];
- is_dev = strncmp (filename, "/dev/", 5) == 0;
+ is_dev = STREQLEN (filename, "/dev/", 5);
if (!is_dev) CHROOT_IN;
fd = open (filename, O_RDONLY);
int len = strlen (vgs[i]);
int j;
for (j = 0; lvs[j] != NULL; ++j) {
- if (strncmp (lvs[j], "/dev/", 5) == 0 &&
- strncmp (&lvs[j][5], vgs[i], len) == 0 &&
+ if (STREQLEN (lvs[j], "/dev/", 5) &&
+ STREQLEN (&lvs[j][5], vgs[i], len) &&
lvs[j][len+5] == '/') {
int64_t size;
CALL (size = guestfs_blockdev_getsize64 (g, lvs[j]), -1);
printf ("<windows/>\n");
else if (strstr (what, "boot sector") != NULL)
display_partitions (g, dev);
- else if (strncmp (what, "LVM2", 4) == 0)
+ else if (STREQLEN (what, "LVM2", 4))
printf ("<physvol/>\n");
else if (strstr (what, "ext2 filesystem data") != NULL)
display_ext234 (g, dev, "ext2");
len = strlen (dev);
for (i = 0; parts[i] != NULL; ++i) {
/* Only display partition if it's in the device. */
- if (strncmp (parts[i], dev, len) == 0) {
+ if (STREQLEN (parts[i], dev, len)) {
int64_t size;
CALL (size = guestfs_blockdev_getsize64 (g, parts[i]), -1);
printf ("<partition dev=\"%s\" size=\"%" PRIi64 "\">\n", parts[i], size);
} while (0)
/* Is it a device? */
- if (len < 5 || strncmp (text, "/dev/", 5) == 0) {
+ if (len < 5 || STREQLEN (text, "/dev/", 5)) {
/* Get a list of everything that can possibly begin with /dev/ */
strs = guestfs_list_devices (g);
APPEND_STRS_AND_FREE;
unlink (filename);
/* Changed? */
- if (strlen (content) == size && strncmp (content, content_new, size) == 0) {
+ if (strlen (content) == size && STREQLEN (content, content_new, size)) {
free (content);
free (content_new);
return 0;
setpwent ();
while ((pw = getpwent ()) != NULL) {
if (strlen (pw->pw_name) == ulen &&
- strncmp (username, pw->pw_name, ulen) == 0)
+ STREQLEN (username, pw->pw_name, ulen))
return pw->pw_dir;
}
} __attribute__((__packed__));
#define BLOCK_ID_EQ(h,offs,eqid) \
- (strncmp (((struct ntreg_hbin_block *)((h)->addr + (offs)))->id, (eqid), 2) == 0)
+ (STREQLEN (((struct ntreg_hbin_block *)((h)->addr + (offs)))->id, (eqid), 2))
static size_t
block_len (hive_h *h, size_t blkoff, int *used)
/* Print out any environment variables which may relate to this test. */
for (i = 0; environ[i] != NULL; ++i)
- if (strncmp (environ[i], "LIBGUESTFS_", 11) == 0)
+ if (STREQLEN (environ[i], "LIBGUESTFS_", 11))
printf ("%s\n", environ[i]);
/* Create the handle and configure it. */