tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
7
Task/Program-name/C/program-name-1.c
Normal file
7
Task/Program-name/C/program-name-1.c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("Executable: %s\n", argv[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
Task/Program-name/C/program-name-2.c
Normal file
8
Task/Program-name/C/program-name-2.c
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("This code was in file %s in function %s, at line %d\n",\
|
||||
__FILE__, __FUNCTION__, __LINE__);
|
||||
return 0;
|
||||
}
|
||||
37
Task/Program-name/C/program-name-3.c
Normal file
37
Task/Program-name/C/program-name-3.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* myname.c */
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h> /* struct kinfo_proc */
|
||||
#include <err.h>
|
||||
#include <fcntl.h> /* O_RDONLY */
|
||||
#include <kvm.h>
|
||||
#include <limits.h> /* _POSIX2_LINE_MAX */
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
extern char *__progname; /* from crt0.o */
|
||||
|
||||
struct kinfo_proc *procs;
|
||||
kvm_t *kd;
|
||||
int cnt;
|
||||
char errbuf[_POSIX2_LINE_MAX];
|
||||
|
||||
printf("argv[0]: %s\n", argv[0]);
|
||||
printf("__progname: %s\n", __progname);
|
||||
|
||||
kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
|
||||
if (kd == NULL)
|
||||
errx(1, "%s", errbuf);
|
||||
procs = kvm_getprocs(kd, KERN_PROC_PID, getpid(),
|
||||
sizeof procs[0], &cnt);
|
||||
if (procs == NULL)
|
||||
errx(1, "%s", kvm_geterr(kd));
|
||||
if (cnt != 1)
|
||||
errx(1, "impossible");
|
||||
|
||||
printf("p_comm: %s\n", procs[0].p_comm);
|
||||
|
||||
kvm_close(kd);
|
||||
return 0;
|
||||
}
|
||||
57
Task/Program-name/C/program-name-4.c
Normal file
57
Task/Program-name/C/program-name-4.c
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
|
||||
/*
|
||||
* Returns the path to the current executable file, in a newly
|
||||
* allocated buffer. Use free() to free it.
|
||||
*/
|
||||
wchar_t *
|
||||
exepath(void)
|
||||
{
|
||||
wchar_t *buf, *newbuf;
|
||||
long blen, flen;
|
||||
|
||||
/*
|
||||
* Most paths fit in MAX_PATH == 260 characters, but very
|
||||
* long UNC paths might require a larger buffer.
|
||||
*/
|
||||
buf = NULL;
|
||||
for (blen = MAX_PATH; 1; blen += MAX_PATH) {
|
||||
/* Enlarge buffer. */
|
||||
newbuf = realloc(buf, blen * sizeof buf[0]);
|
||||
if (newbuf == NULL) {
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
buf = newbuf;
|
||||
|
||||
flen = GetModuleFileNameW(NULL, buf, blen);
|
||||
if (flen == 0) {
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
if (flen < blen)
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Print the path to this executable.
|
||||
*/
|
||||
int
|
||||
main()
|
||||
{
|
||||
wchar_t *path;
|
||||
|
||||
path = exepath();
|
||||
if (path == NULL) {
|
||||
wprintf(L"Sorry, an error occured.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
wprintf(L"Path to executable: %ls\n", path);
|
||||
|
||||
free(path);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue