view toys/other/pwdx.c @ 1189:95ae2805622f draft

Add Szabolcs Nagy's deflate/inflate code from git://git.suckless.org/flate Confirmed with him on IRC it's ok to use under toybox license, glued the files together and hammered square peg into round hole, no other changes yet.
author Rob Landley <rob@landley.net>
date Fri, 31 Jan 2014 06:01:30 -0600
parents 0752b2d58909
children
line wrap: on
line source

/* pwdx.c - report current directory of a process. 
 *
 * Copyright 2013 Lukasz Skalski <l.skalski@partner.samsung.com>

USE_PWDX(NEWTOY(pwdx, "<1a", TOYFLAG_USR|TOYFLAG_BIN))

config PWDX
  bool "pwdx"
  default y
  help
    usage: pwdx PID...

    Print working directory of processes listed on command line.
*/

#include "toys.h"

void pwdx_main(void)
{
  char **optargs;

  for (optargs = toys.optargs; *optargs; optargs++) {
    char *path;
    int num_bytes;

    path = xmprintf("/proc/%s/cwd", *optargs);
    num_bytes = readlink(path, toybuf, sizeof(toybuf)-1);
    free(path);

    if (num_bytes==-1) {
      path = strerror(errno);
      toys.exitval = 1;
    } else {
      path = toybuf;
      toybuf[num_bytes] = 0;
    }
    xprintf("%s: %s\n", *optargs, path);
  }
}