File: misc.c

package info (click to toggle)
reiser4progs 1.0.7-6
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,352 kB
  • ctags: 3,699
  • sloc: ansic: 33,483; sh: 8,489; makefile: 1,001
file content (38 lines) | stat: -rw-r--r-- 761 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Copyright (C) 2001-2005 by Hans Reiser, licensing governed by
   reiser4progs/COPYING.
   
   misc.c -- miscellaneous useful stuff. */

#include "busy.h"

reiser4_object_t *busy_misc_open_parent(reiser4_tree_t *tree, 
					char **path)
{
	reiser4_object_t *object;
	char *sep;
	
	if (!(sep = aal_strrchr(*path, '/'))) {
		aal_error("Wrong PATH format is detected: %s.", *path);
		return INVAL_PTR;
	}

	if (sep == *path) {
		/* Create file in the root. */
		object = reiser4_semantic_open(tree, "/", NULL, 1);
	} else {
		sep[0] = 0;
		object = reiser4_semantic_open(tree, *path, NULL, 1);
		sep[0] = '/';
	}
	
	if (!object) {
		aal_error("Can't open file %s.", *path);
		sep[0] = '/';
		return NULL;
	}
	
	sep[0] = '/';
	*path = sep + 1;

	return object;
}