mirror of
git://git.suckless.org/ubase
synced 2024-12-22 22:53:10 +00:00
Add swapon(8)
No manpage yet.
This commit is contained in:
parent
0c37fe11e4
commit
601e4ad5f9
3
Makefile
3
Makefile
@ -24,7 +24,8 @@ SRC += \
|
||||
mkswap.c \
|
||||
reboot.c \
|
||||
rmmod.c \
|
||||
swapoff.c
|
||||
swapoff.c \
|
||||
swapon.c
|
||||
endif
|
||||
|
||||
OBJ = $(SRC:.c=.o) $(LIB)
|
||||
|
41
swapon.c
Normal file
41
swapon.c
Normal file
@ -0,0 +1,41 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <sys/swap.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "util.h"
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
eprintf("usage: %s [-d] swapfile\n", argv0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int ret = 0;
|
||||
int flags = 0;
|
||||
|
||||
ARGBEGIN {
|
||||
case 'd':
|
||||
flags |= SWAP_FLAG_DISCARD;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
} ARGEND;
|
||||
|
||||
if (argc < 1)
|
||||
usage();
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
ret = swapon(argv[i], flags);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "swapon %s: %s\n",
|
||||
argv[i], strerror(errno));
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user