view toys/lsb/mknod.c @ 694:786841fdb1e0

Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style. The actual code should be the same afterward, this is just cosmetic refactoring.
author Rob Landley <>
date Tue, 13 Nov 2012 17:14:08 -0600
parents 7e846e281e38
children d7e43cc0f525
line wrap: on
line source

/* mknod.c - make block or character special file
 * Copyright 2012 Elie De Brauwer <>


config MKNOD
  bool "mknod"
  default y
    usage: mknod NAME TYPE [MAJOR MINOR]

    Create a special file NAME with a given type, possible types are
    b	block device
    c or u	character device
    p	named pipe (ignores MAJOR/MINOR)

#define FOR_mknod
#include "toys.h"

void mknod_main(void)
  mode_t modes[] = {S_IFIFO, S_IFCHR, S_IFCHR, S_IFBLK};
  int major=0, minor=0, type;
  int mode = 0660;

  type = stridx("pcub", *toys.optargs[1]);
  if (type == -1) perror_exit("bad type '%c'", *toys.optargs[1]);
  if (type) {
    if (toys.optc != 4) perror_exit("need major/minor");

    major = atoi(toys.optargs[2]);
    minor = atoi(toys.optargs[3]);

  if (mknod(toys.optargs[0], mode | modes[type], makedev(major, minor)))
    perror_exit("mknod %s failed", toys.optargs[0]);