1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

Everywhere: Add serenity_dev_{makedev,major,minor}

Add them in `<Kernel/API/Device.h>` and use these to provides
`{makedev,major,minor}` in `<sys/sysmacros.h>`. It aims to be more in
line with other Unix implementations and avoid code duplication in user
land.
This commit is contained in:
Michel Hermier 2021-11-26 16:55:45 +01:00 committed by Andreas Kling
parent d4484f4de3
commit 69cabb3ead
7 changed files with 43 additions and 17 deletions

View file

@ -8,13 +8,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <unistd.h>
constexpr unsigned encoded_device(unsigned major, unsigned minor)
{
return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
}
static int usage()
{
warnln("usage: mknod <name> <c|b|p> [<major> <minor>]");
@ -63,7 +59,7 @@ int main(int argc, char** argv)
minor = atoi(argv[4]);
}
int rc = mknod(name, mode, encoded_device(major, minor));
int rc = mknod(name, mode, makedev(major, minor));
if (rc < 0) {
perror("mknod");
return 1;