#include #include #include static int my_write(int fd, const char *s, size_t l) { if (!l) l = strlen(s); while (l) { ssize_t n = write(fd, s, l); if (n<0) return -1; s += n; l -= n; } return 0; } int main(int argc, char *argv[]) { char *s; if (argc != 2) { my_write(2, argv[0], 0); my_write(2, ": missing operand\n", 0); return 1; } s = dirname(argv[1]); if (my_write(1, s, 0)<0 || my_write(1, "\n", 1)<0) return 1; return 0; }