logo

utils

~/.local/bin tools and git-hooks

pwd.c (628B)


      1 // Copyright 2018 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
      2 // Distributed under the terms of the CC-BY-SA-4.0 license
      3 
      4 #include <errno.h>  /* errno */
      5 #include <stdio.h>  /* puts, perror, printf */
      6 #include <stdlib.h> /* exit */
      7 #include <string.h> /* strerror */
      8 #include <unistd.h> /* getcwd() */
      9 
     10 char buf[BUFSIZ];
     11 
     12 void usage(char *a0)
     13 {
     14 	(void)printf("usage: %s\n", a0);
     15 	exit(EXIT_SUCCESS);
     16 }
     17 
     18 int main(int argc, char *argv[])
     19 {
     20 	if(argc != 1) usage(argv[0]);
     21 
     22 	if(getcwd(buf, sizeof(buf)) == NULL)
     23 	{
     24 		perror(strerror(errno));
     25 		exit(EXIT_FAILURE);
     26 	}
     27 	else
     28 	{
     29 		const char *pwd = buf;
     30 		return puts(pwd);
     31 	}
     32 }