aboutsummaryrefslogtreecommitdiffstats
path: root/swall/swall.c
blob: 97865f103a6285e34288e4538d32cfe084c00573 (plain) (blame)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

int file_exis(const char * file_name) {
	FILE * fp;

	if ((fp = fopen(file_name, "r"))) {
		fclose(fp);
		return 1;
	}

	return 0;
}

int main(int argc, char ** argv) {
	int i;

	if (argc < 2) {
		fputs("No arguments found.\n", stderr);
		return -1;
	}

	size_t the_size = strlen(argv[1]);
	char msg[the_size];
	memset(msg, 0, the_size);

	strncat(msg, argv[1], sizeof(msg));

	for (i = 2; i < argc; i++) {
		strncat(msg, " ", the_size);
		strncat(msg, argv[i], the_size);
	}

	char com[100];
	char file_msg[15];

	for (i = 0; i < 100; i++) {
		snprintf(file_msg, sizeof(file_msg), "/dev/pts/%d", i);

		if (file_exis(file_msg)) {
			snprintf(com, sizeof(com), "%s > %s", msg, file_msg);
			system(com);
		}

		snprintf(file_msg, sizeof(file_msg), "/dev/tty%d", i);

		if (file_exis(file_msg)) {
			snprintf(com, sizeof(com), "%s > %s", msg, file_msg);
			system(com);
		}
	}


	return 0;
}