예제 #1
0
li_object * g1_path_object_class::message(li_symbol * message_name,
										  li_object * message_params,
										  li_environment * env)
{
	li_class_context context(vars);

	if (message_name==on.get() || message_name==off.get())
	{
		active() = on.get();
	}
	else if (message_name==s_add_link.get())
	{
		g1_object_class * o=li_g1_ref::get(message_params,env)->value();
		g1_path_object_class * path = g1_path_object_class::cast(o);

		if (path)
		{
			add_link(G1_ALLY, path);
			path->add_link(G1_ENEMY, this);
		}
	}
	else if (message_name==s_remove_link.get())
	{
		g1_object_class * o=li_g1_ref::get(message_params,env)->value();
		g1_path_object_class * path = g1_path_object_class::cast(o);

		if (path)
		{
			remove_link(G1_ALLY, path);
			path->remove_link(G1_ENEMY, this);
		}
	}

	return 0;
}
예제 #2
0
void linked_list<T>::clear() {
    // until there are no more links, delete the link
    while(head->next != NULL) // start _after_ the dummy node
        remove_link(head);
    tail = head; // empty list
    list_size = 0;
    modified = true;
}
예제 #3
0
파일: fifo.c 프로젝트: svkampen/Apollo
void destroy(struct bot *bot) {
	struct double_link *i, *next;
	for (struct double_link *i = bot->tick_functions; i != NULL; i = next) {
		next = i->next;
		if (i->ptr == fifo_tick) {
			remove_link(i);
		}
	}
}
예제 #4
0
파일: danlian2.c 프로젝트: wsIThp/C-project
int main(void)
{
	STU *head = NULL;
    
	head = create_link(10);
   //head=add_note(head);
    head =  remove_link(head);
	print_link(head);
	return 0;
}
예제 #5
0
void monitorable_actor::unlink_from(const actor_addr& x) {
  auto ptr = actor_cast<strong_actor_ptr>(x);
  if (ptr != nullptr) {
    if (ptr->get() != this)
      remove_link(ptr->get());
  } else {
    default_attachable::observe_token tk{x, default_attachable::link};
    exclusive_critical_section([&] {
      detach_impl(tk, true);
    });
  }
}
예제 #6
0
파일: fs.c 프로젝트: champo/ArqvengerOS
int fs_rmdir(struct fs_Inode* path, const char* name) {

    struct fs_DirectoryEntry entry = fs_findentry(path, name);
    if (!entry.inode) {
        return ENOENT;
    }

    struct fs_Inode* dir = fs_inode_open(entry.inode);
    if (dir == NULL) {
        return EIO;
    }

    if (INODE_TYPE(dir->data) != INODE_DIR) {
        fs_inode_close(dir);
        return ENOTDIR;
    }

    size_t offset = 0;
    struct DirectoryEntry child = ext2_dir_read(dir, offset);
    while (child.entryLength != 0) {
        if (child.inode != path->number && child.inode != entry.inode) {
            fs_inode_close(dir);
            return ENOTEMPTY;
        }

        offset += child.entryLength;
        child = ext2_dir_read(dir, offset);
    }

    int res = remove_link(path, name, dir);
    if (dir->data->hardLinks == 1) {
        remove_link(dir, ".", dir);
        remove_link(dir, "..", path);
    }
    fs_inode_close(dir);

    return res;
}
예제 #7
0
T linked_list<T>::remove(int position) {
    if(position < 0 || position >= list_size)
        throw invalid_position_exception();

    // move a link pointer to the desired position (point to link "position")
    link* current = move(head, position);
    T element = remove_link(current);

    // reset the tail if we're removing the last link
    if(current->next == NULL)
        tail = current;
	
    list_size--;
    modified = true;

    return element;
}
예제 #8
0
파일: copydir.c 프로젝트: bfeeny/shadow
/*
 * copy_hardlink - copy a hardlink
 *
 *	Copy a hardlink from src to dst.
 *
 *	Return 0 on success, -1 on error.
 */
static int copy_hardlink (const char *dst,
                          unused bool reset_selinux,
                          struct link_name *lp)
{
    /* FIXME: selinux, ACL, Extended Attributes needed? */

    if (link (lp->ln_name, dst) != 0) {
        return -1;
    }

    /* If the file could be unlinked, decrement the links counter,
     * and forget about this link if it was the last reference */
    lp->ln_count--;
    if (lp->ln_count <= 0) {
        remove_link (lp);
    }

    return 0;
}
예제 #9
0
void	ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)())
{
	t_list	*node;
	t_list	*prev;

	prev = NULL;
	node = *begin_list;
	while (node != NULL)
	{
		if ((*cmp)(data_ref, node->data) == 0)
		{
			remove_link(begin_list, &node, &prev);
		}
		else
		{
			prev = node;
			node = node->next;
		}
	}
}
예제 #10
0
파일: fs.c 프로젝트: champo/ArqvengerOS
int fs_unlink(struct fs_Inode* path, const char* name) {

    struct fs_DirectoryEntry entry = fs_findentry(path, name);
    if (!entry.inode) {
        return ENOENT;
    }

    struct fs_Inode* inode = fs_inode_open(entry.inode);
    if (inode == NULL) {
        return EIO;
    }
    if (INODE_TYPE(inode->data) == INODE_DIR) {
        fs_inode_close(inode);
        return EISDIR;
    }

    int res = remove_link(path, name, inode);
    fs_inode_close(inode);

    return res;
}
예제 #11
0
/*
 * copy_hardlink - copy a hardlink
 *
 *	Copy a hardlink from src to dst.
 *
 *	Return 0 on success, -1 on error.
 */
static int copy_hardlink (const char *src, const char *dst,
                          struct link_name *lp)
{
	/* TODO: selinux needed? */

	if (link (lp->ln_name, dst) != 0) {
		return -1;
	}

	/* FIXME: why is it unlinked? This is a copy, not a move */
	if (unlink (src) != 0) {
		return -1;
	}

	/* FIXME: idem, although it may never be used again */
	/* If the file could be unlinked, decrement the links counter,
	 * and delete the file if it was the last reference */
	lp->ln_count--;
	if (lp->ln_count <= 0) {
		remove_link (lp);
	}

	return 0;
}
예제 #12
0
파일: remove.c 프로젝트: lord0gnome/lem-in
static void	test_duplicates(t_l_rooms *room)
{
	t_l_links	*cl;
	t_l_links	*rbck;

	cl = room->links;
	rbck = room->links;
	while (rbck)
	{
		cl = rbck;
		while (cl)
		{
			cl = cl->next;
			if (cl && rbck && cl != rbck && rbck->roomptr == cl->roomptr)
			{
				remove_link(room->links, cl);
				break ;
			}
		}
		if (cl)
			continue ;
		rbck = rbck->next;
	}
}
예제 #13
0
파일: copydir.c 프로젝트: OPSF/uClinux
int copy_tree (const char *src_root, const char *dst_root, uid_t uid, gid_t gid)
{
	char src_name[1024];
	char dst_name[1024];
	char buf[1024];
	int ifd;
	int ofd;
	int err = 0;
	int cnt;
	int set_orig = 0;
	struct DIRECT *ent;
	struct stat sb;
	struct link_name *lp;
	DIR *dir;

	/*
	 * Make certain both directories exist.  This routine is called
	 * after the home directory is created, or recursively after the
	 * target is created.  It assumes the target directory exists.
	 */

	if (access (src_root, F_OK) != 0 || access (dst_root, F_OK) != 0)
		return -1;

	/*
	 * Open the source directory and read each entry.  Every file
	 * entry in the directory is copied with the UID and GID set
	 * to the provided values.  As an added security feature only
	 * regular files (and directories ...) are copied, and no file
	 * is made set-ID.
	 */

	if (!(dir = opendir (src_root)))
		return -1;

	if (src_orig == 0) {
		src_orig = src_root;
		dst_orig = dst_root;
		set_orig++;
	}
	while ((ent = readdir (dir))) {

		/*
		 * Skip the "." and ".." entries
		 */

		if (strcmp (ent->d_name, ".") == 0 ||
		    strcmp (ent->d_name, "..") == 0)
			continue;

		/*
		 * Make the filename for both the source and the
		 * destination files.
		 */

		if (strlen (src_root) + strlen (ent->d_name) + 2 >
		    sizeof src_name) {
			err++;
			break;
		}
		snprintf (src_name, sizeof src_name, "%s/%s", src_root,
			  ent->d_name);

		if (strlen (dst_root) + strlen (ent->d_name) + 2 >
		    sizeof dst_name) {
			err++;
			break;
		}
		snprintf (dst_name, sizeof dst_name, "%s/%s", dst_root,
			  ent->d_name);

		if (LSTAT (src_name, &sb) == -1)
			continue;

		if (S_ISDIR (sb.st_mode)) {

			/*
			 * Create a new target directory, make it owned by
			 * the user and then recursively copy that directory.
			 */

#ifdef WITH_SELINUX
			selinux_file_context (dst_name);
#endif
			mkdir (dst_name, sb.st_mode & 0777);
			chown (dst_name,
			       uid == (uid_t) - 1 ? sb.st_uid : uid,
			       gid == (gid_t) - 1 ? sb.st_gid : gid);

			if (copy_tree (src_name, dst_name, uid, gid)) {
				err++;
				break;
			}
			continue;
		}
#ifdef	S_IFLNK
		/*
		 * Copy any symbolic links
		 */

		if (S_ISLNK (sb.st_mode)) {
			char oldlink[1024];
			char dummy[1024];
			int len;

			/*
			 * Get the name of the file which the link points
			 * to.  If that name begins with the original
			 * source directory name, that part of the link
			 * name will be replaced with the original
			 * destinateion directory name.
			 */

			if ((len =
			     readlink (src_name, oldlink,
				       sizeof (oldlink) - 1)) < 0) {
				err++;
				break;
			}
			oldlink[len] = '\0';	/* readlink() does not NUL-terminate */
			if (!strncmp (oldlink, src_orig, strlen (src_orig))) {
				snprintf (dummy, sizeof dummy, "%s%s",
					  dst_orig,
					  oldlink + strlen (src_orig));
				strcpy (oldlink, dummy);
			}
#ifdef WITH_SELINUX
			selinux_file_context (dst_name);
#endif
			if (symlink (oldlink, dst_name) ||
			    lchown (dst_name,
				    uid == (uid_t) - 1 ? sb.st_uid : uid,
				    gid == (gid_t) - 1 ? sb.st_gid : gid)) {
				err++;
				break;
			}
			continue;
		}
#endif

		/*
		 * See if this is a previously copied link
		 */

		if ((lp = check_link (src_name, &sb))) {
			if (link (lp->ln_name, dst_name)) {
				err++;
				break;
			}
			if (unlink (src_name)) {
				err++;
				break;
			}
			if (--lp->ln_count <= 0)
				remove_link (lp);

			continue;
		}

		/*
		 * Deal with FIFOs and special files.  The user really
		 * shouldn't have any of these, but it seems like it
		 * would be nice to copy everything ...
		 */

		if (!S_ISREG (sb.st_mode)) {
#ifdef WITH_SELINUX
			selinux_file_context (dst_name);
#endif
			if (mknod (dst_name, sb.st_mode & ~07777, sb.st_rdev)
			    || chown (dst_name,
				      uid == (uid_t) - 1 ? sb.st_uid : uid,
				      gid == (gid_t) - 1 ? sb.st_gid : gid)
			    || chmod (dst_name, sb.st_mode & 07777)) {
				err++;
				break;
			}
			continue;
		}

		/*
		 * Create the new file and copy the contents.  The new
		 * file will be owned by the provided UID and GID values.
		 */

		if ((ifd = open (src_name, O_RDONLY)) < 0) {
			err++;
			break;
		}
#ifdef WITH_SELINUX
		selinux_file_context (dst_name);
#endif
		if ((ofd =
		     open (dst_name, O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0
		    || chown (dst_name,
			      uid == (uid_t) - 1 ? sb.st_uid : uid,
			      gid == (gid_t) - 1 ? sb.st_gid : gid)
		    || chmod (dst_name, sb.st_mode & 07777)) {
			close (ifd);
			err++;
			break;
		}
		while ((cnt = read (ifd, buf, sizeof buf)) > 0) {
			if (write (ofd, buf, cnt) != cnt) {
				cnt = -1;
				break;
			}
		}
		close (ifd);
		close (ofd);

		if (cnt == -1) {
			err++;
			break;
		}
	}
	closedir (dir);

	if (set_orig) {
		src_orig = 0;
		dst_orig = 0;
	}
	return err ? -1 : 0;
}
예제 #14
0
파일: DAWG.C 프로젝트: TRI0N/WWIVTOSS
void deletemsg(int mn)
{
  postrec *p1, p;
  int close_file=0;
  unsigned int nb;
  char *buf;
//  char scratch[181];
  long len, l, cp;

  /* open file, if needed */
  if (sub_f <= 0) {
    open_sub(1);
    close_file=1;
  }

  /* see if anything changed */
  read_status();

  if (sub_f >= 0) {
    if ((mn>0) && (mn<=nummsgs)) {
      buf=(char *)malloca(BUFSIZE);
      if (buf) {
        p1=get_post(mn);
        remove_link(&(p1->msg),(subboards[curlsub].filename));

        cp=((long)mn+1)*sizeof(postrec);
        len=((long)(nummsgs+1))*sizeof(postrec);

        do {
          l=len-cp;
          if (l<BUFSIZE)
            nb=(int)l;
          else
            nb=BUFSIZE;
          if (nb) {
            sh_lseek(sub_f, cp, SEEK_SET);
            sh_read(sub_f, buf, nb);
            sh_lseek(sub_f, cp-sizeof(postrec), SEEK_SET);
            sh_write(sub_f, buf, nb);
            cp += nb;
          }
        } while (nb==BUFSIZE);

        /* update # msgs */
        sh_lseek(sub_f, 0L, SEEK_SET);
        sh_read(sub_f, &p, sizeof(postrec));
        p.owneruser--;
        nummsgs=p.owneruser;
        sh_lseek(sub_f, 0L, SEEK_SET);
        sh_write(sub_f, &p, sizeof(postrec));

        /* cache is now invalid */
        believe_cache = 0;

        bbsfree(buf);
      }
    }
  }

  /* close file, if needed */
  if (close_file)
    close_sub();

}