view toys/other/pwdx.c @ 1539:3e85af1f7e22 draft

First batch of sed tests. Only good for TEST_HOST=1 at the moment because the test infrastructure itself depends on sed, so if an unfinished sed is in the $PATH it goes boing. But hey, corner cases! I have... more.
author Rob Landley <>
date Wed, 29 Oct 2014 18:44:33 -0500
parents 0752b2d58909
line wrap: on
line source

/* pwdx.c - report current directory of a process. 
 * Copyright 2013 Lukasz Skalski <>


config PWDX
  bool "pwdx"
  default y
    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);

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