[PATCH v1] tests: getcwd.test

Dmitry V. Levin ldv at altlinux.org
Sun Mar 20 01:38:03 UTC 2016


On Sun, Mar 20, 2016 at 01:19:16AM +0530, Jay Joshi wrote:
> --- /dev/null
> +++ b/tests/getcwd.c
> @@ -0,0 +1,40 @@
> +#include "tests.h"
> +
> +#include <sys/syscall.h>
> +
> +#ifdef __NR_getcwd
> +
> +# include <stdio.h>
> +# include <unistd.h>
> +# include <errno.h>

<nitpick> You no longer need <errno.h>. </nitpick>

> +# include <sys/param.h>
> +
> +int
> +main(void)
> +{
> +  long res;
> +  char cur_dir[PATH_MAX + 1];
> +
> +  res = syscall(__NR_getcwd, cur_dir, sizeof(cur_dir));
> +
> +  if (res <= 0)
> +    perror_msg_and_fail("getcwd");
> +
> +  printf("getcwd(\"");
> +  print_quoted_string(cur_dir);
> +  printf("\", %zu) = %ld\n", sizeof(cur_dir), res);
> +
> +  syscall(__NR_getcwd, cur_dir, 0);
> +
> +  printf("getcwd(%p, 0) = -1 ERANGE (%m)\n", cur_dir);
> +
> +  puts("+++ exited with 0 +++");
> +
> +  return 0;
> +}

Please reindent with TABs.

> --- /dev/null
> +++ b/tests/getcwd.test
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +# Check getcwd syscall decoding

This sentence should end with a period.

> +print_quoted_string(const char *str)
> +{
> +	unsigned int i=0;
> +	int c;
> +
> +	while ((c = str[i++]) != '\0') {

Wouldn't it be better without an iterator?  e.g.
	while ((c = *(str++))) {

> +				if (c >= ' ' && c <= 0x7e)
> +					printf("%c",c);

Wouldn't putchar(c) in cases like this look simpler?

> +  printf("\0");

What is this?

> --- a/tests/tests.h
> +++ b/tests/tests.h
> @@ -75,6 +75,9 @@ const char *hexquote_strndup(const char *, size_t);
>  /* Return inode number of socket descriptor. */
>  unsigned long inode_of_sockfd(int);
>  
> +/* Print string in escaped format */
This sentence should end with a period.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160320/cf44407f/attachment.bin>


More information about the Strace-devel mailing list