1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 ss_scope_t *
 ss_pers_topscope(ss_pers_t *pers,               /* Persistent object link to query */
                  ss_scope_t *buf                /* OUT: Optional buffer for the result scope link */
                  )
 {
     SS_ENTER(ss_pers_topscope, ss_scope_tP);
     ss_scope_t          *buf_here=NULL;
     ss_gfile_t          *gfile=NULL;

     SS_ASSERT_CLASS(pers, ss_pers_t);
     if (SS_PERS_LINK_NULL==ss_pers_link_state(pers)) SS_ERROR_FMT(NOTFOUND, ("null persistent link"));
     if (SS_PERS_LINK_RESERVED==ss_pers_link_state(pers)) SS_ERROR_FMT(CORRUPT, ("mangled persistent link"));

     if (NULL==(gfile = SS_GFILE_LINK(pers))) SS_ERROR(FAILED);
     if (gfile->cur_open<=0) SS_ERROR_FMT(NOTFOUND, ("file is closed: %s", gfile->name));
     SS_ASSERT(gfile->topscope);

     if (!buf && NULL==(buf=buf_here=malloc(sizeof(*buf)))) SS_ERROR(RESOURCE);
     *buf = *(gfile->topscope);

  SS_CLEANUP:
     SS_FREE(buf_here);
     SS_LEAVE(buf);
 }