Esempio n. 1
0
int main(int argc, char *argv[])
{
  tinydir_file file;
  if (argc != 2)
  {
    fprintf(stderr, "Usage: test filename\n");
    return 1;
  }
  if (tinydir_file_open(&file, argv[1]) == -1)
  {
    perror("Error opening file");
    return 1;
  }
  printf("Path: %s\nName: %s\nExtension: %s\nIs dir? %s\nIs regular file? %s\n",
       file.path, file.name, file.extension,
       file.is_dir?"yes":"no", file.is_reg?"yes":"no");
  return 0;
}
Esempio n. 2
0
		if (strncmp(out, ".\\", 2) == 0)
		{
			memmove(out, out + 2, strlen(out));
		}
		// Create file
		fclose(fopen(out, "w"));
	}
#else
	#include <stdlib.h>
	#include <unistd.h>
	sprintf(out, "%sXXXXXX", prefix);
	close(mkstemp(out));
#endif
}

FEATURE(file_open, "File open")
	SCENARIO("Open file in current directory")
		GIVEN("a file in the current directory")
			char name[4096];
			make_temp_file("temp_file_", name);
		WHEN("we open it")
			tinydir_file file;
			int r = tinydir_file_open(&file, name);
		THEN("the result should be successful")
			SHOULD_INT_EQUAL(r, 0);
		remove(name);
	SCENARIO_END
FEATURE_END

CBEHAVE_RUN("File open:", TEST_FEATURE(file_open))