示例#1
0
static int chips_trunc(int argc, char **argv)
{
	if(argc < 2 || argc > 3)
	{
		fprintf(stderr, "Usage: %s <file> [size]\n", argv[0]);
		return -1;
	}
	int size = 0;
	if(argc == 3)
	{
		char *end;
		size = strtol(argv[2], &end, 0);
		if(*end != 0 || size < 0)
		{
			fprintf(stderr, "Not a nonnegative integer: %s\n", argv[2]);
			return -1;
		}
	}

	if(!fs_truncate(argv[1], size))
	{
		fprintf(stderr, "Truncating %s failed.\n", argv[1]);
		return 1;
	}
	return 0;
}
示例#2
0
/*
 * Change the size of an open file.  Very similar to fs_truncate (and,
 * depending on your implementation), you could possibly treat it the
 * same as fs_truncate.
 */
int fs_ftruncate(const char *path, off_t offset, struct fuse_file_info *fi) {
    fprintf(stderr, "fs_ftruncate(path=\"%s\", offset=%d)\n", path, (int)offset);
    s3context_t *ctx = GET_PRIVATE_DATA;
	int err = NULL;
	if((err=fs_truncate(path, offset))!=0) {
		fprintf(stderr, "error truncating path: fs_ftruncate\n");
		return -errno;
	}
    return 0;
}
示例#3
0
/*
	trunc command
*/
LOCAL	void	cmd_trunc(INT ac, B *av[])
{
	ER	er;
	INT	len;

	if (ac < 3) return;

	len = strtol(av[2], NULL, 0);

	er = fs_truncate(av[1], len);
	if (er >= E_OK) {
		P("'%s' is truncated to %d\n", av[1], len);
	} else {
		P("fs_truncate(%s, %d) ERR [%#x]\n", av[1], len, er);
	}
}
示例#4
0
文件: ecmd.c 项目: EtherGraf/ethersex
int16_t
parse_cmd_fs_truncate (char *cmd, char *output, uint16_t len)
{
  /* Ignore leading spaces. */
  while (* cmd == ' ') cmd ++;

  char *ptr = strchr (cmd, ' ');
  if (ptr == NULL) return ECMD_ERR_PARSE_ERROR;	/* invalid args. */

  *(ptr ++) = 0;		/* Zero terminate filename. */

  fs_inode_t i = fs_get_inode (&fs, cmd);

  if (i == 0xffff)
    return ECMD_FINAL(snprintf_P(output, len, PSTR("no such file.")));

  fs_status_t ret = fs_truncate (&fs, i, strtoul (ptr, NULL, 10));
  return (ret == FS_OK) ? ECMD_FINAL_OK : ECMD_ERR_PARSE_ERROR;
}
示例#5
0
static int chips_truncate(const char *path, off_t offset)
{
	return fs_truncate((char *)path, offset) ? 0 : -1;
}