added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / dos / attemptlockdoslist.c
blob5f277b0c2c863e07c3a41ee81a1366f535171f5a
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
8 #include <aros/debug.h>
9 #include <proto/exec.h>
10 #include "dos_intern.h"
12 /*****************************************************************************
14 NAME */
15 #include <proto/dos.h>
17 AROS_LH1(struct DosList *, AttemptLockDosList,
19 /* SYNOPSIS */
20 AROS_LHA(ULONG, flags, D1),
22 /* LOCATION */
23 struct DosLibrary *, DOSBase, 111, Dos)
25 /* FUNCTION
26 Tries to get a lock on some of the dos lists. If all went
27 well a handle is returned that can be used for FindDosEntry().
28 Don't try to busy wait until the lock can be granted - use
29 LockDosList() instead.
31 INPUTS
32 flags -- what lists to lock
34 RESULT
35 Handle to the dos list or NULL. This is not a direct pointer
36 to the first list element but to a pseudo element instead.
38 NOTES
40 EXAMPLE
42 BUGS
44 SEE ALSO
46 INTERNALS
48 HISTORY
49 04-06-07 sonic merged back from MorphOS source code
50 29-10-95 digulla automatically created from
51 dos_lib.fd and clib/dos_protos.h
53 *****************************************************************************/
55 AROS_LIBFUNC_INIT
57 struct DosInfo *di = BADDR(DOSBase->dl_Root->rn_Info);
58 struct DosList *dl = (struct DosList *)&DOSBase->dl_DevInfo;
59 ULONG DevSem, EntrySem, DelSem;
61 D(bug("AttemptLockDosList: flags = $%lx\n", flags));
63 if (((flags & (LDF_READ|LDF_WRITE)) != LDF_READ &&
64 (flags & (LDF_READ|LDF_WRITE)) != LDF_WRITE) ||
65 (flags & ~(LDF_READ|LDF_WRITE|LDF_DEVICES|LDF_VOLUMES|LDF_ASSIGNS|LDF_ENTRY|LDF_DELETE)))
66 return NULL;
68 if (flags & LDF_ALL)
70 if (flags & LDF_WRITE)
71 DevSem = AttemptSemaphore(&di->di_DevLock);
72 else
73 DevSem = AttemptSemaphoreShared(&di->di_DevLock);
74 if (!DevSem)
75 dl = NULL;
78 if (flags & LDF_ENTRY)
80 if (flags & LDF_WRITE)
81 EntrySem = AttemptSemaphore(&di->di_EntryLock);
82 else
83 EntrySem = AttemptSemaphoreShared(&di->di_EntryLock);
84 if (!EntrySem)
85 dl = NULL;
88 if (flags & LDF_DELETE)
90 if (flags & LDF_WRITE)
91 DelSem = AttemptSemaphore(&di->di_DeleteLock);
92 else
93 DelSem = AttemptSemaphoreShared(&di->di_DeleteLock);
94 if (!DelSem)
95 dl = NULL;
98 /* This came from MorphOS source code, however looks strange.
99 Commented out but left for reference.
100 if (dl)
101 Forbid(); */
102 if (!dl) {
103 if (DevSem)
104 ReleaseSemaphore(&di->di_DevLock);
105 if (EntrySem)
106 ReleaseSemaphore(&di->di_EntryLock);
107 if (DelSem)
108 ReleaseSemaphore(&di->di_DeleteLock);
111 D(bug("AttemptLockDosList: result = $%lx\n", dl));
113 return dl;
115 AROS_LIBFUNC_EXIT
116 } /* AttemptLockDosList */