* ODBC Under Linux
@ 2003-02-28 3:26 chuckw
2003-02-28 21:31 ` Glynn Clements
0 siblings, 1 reply; 10+ messages in thread
From: chuckw @ 2003-02-28 3:26 UTC (permalink / raw)
To: linux-c-programming
Hello All,
I am trying to write an app. which will have to access a database. I wanted
to write the app so that the backend database could be changed without changing
the app. I know there is ODBC out there, but I was wondering if anyone had
ideas on the best free ODBC, or maybe some better way of doing this.
Thanks
Chuck
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: ODBC Under Linux
2003-02-28 3:26 ODBC Under Linux chuckw
@ 2003-02-28 21:31 ` Glynn Clements
2003-03-19 13:22 ` How to open a file and to disable other processes from removing it Alexi Jordanov
0 siblings, 1 reply; 10+ messages in thread
From: Glynn Clements @ 2003-02-28 21:31 UTC (permalink / raw)
To: chuckw; +Cc: linux-c-programming
chuckw@ieee.org wrote:
> Hello All,
> I am trying to write an app. which will have to access a database. I wanted
> to write the app so that the backend database could be changed without changing
> the app. I know there is ODBC out there, but I was wondering if anyone had
> ideas on the best free ODBC, or maybe some better way of doing this.
I don't know about "best", but the two most popular ODBC managers are
iODBC and unixODBC:
http://www.iodbc.org/
http://www.unixodbc.org/
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 10+ messages in thread
* How to open a file and to disable other processes from removing it
2003-02-28 21:31 ` Glynn Clements
@ 2003-03-19 13:22 ` Alexi Jordanov
2003-03-19 15:45 ` Glynn Clements
0 siblings, 1 reply; 10+ messages in thread
From: Alexi Jordanov @ 2003-03-19 13:22 UTC (permalink / raw)
To: linux-c-programming
Hello to everyone,
Can somebody tell me how to open a file on Linux and to disable other
processes from being capable to remove it?
Regards, Alex
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to open a file and to disable other processes from removing it
2003-03-19 13:22 ` How to open a file and to disable other processes from removing it Alexi Jordanov
@ 2003-03-19 15:45 ` Glynn Clements
2003-03-22 19:47 ` dynamic allocation of array of structures J.
0 siblings, 1 reply; 10+ messages in thread
From: Glynn Clements @ 2003-03-19 15:45 UTC (permalink / raw)
To: Alexi Jordanov; +Cc: linux-c-programming
Alexi Jordanov wrote:
> Can somebody tell me how to open a file on Linux and to disable other
> processes from being capable to remove it?
1. Nothing will prevent root-owned processes from deleting the file.
Anything which you do to prevent it can be undone by root.
2. Unless the process which creates the file is running as root,
nothing will prevent other processes which run under the same account
from deleting it.
If the process which creates the file is running as root, then you can
create the file in a directory which has the sticky bit set, whose
owner differs from that of the file, and which has no permissions for
anyone other than the directory's owner. The sticky bit ensures that
no-one other than the owner can delete it, and the lack of permissions
for the file's owner on the parent directory ensures that the file's
owner cannot reference it (and hence can't delete it).
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 10+ messages in thread
* dynamic allocation of array of structures
2003-03-19 15:45 ` Glynn Clements
@ 2003-03-22 19:47 ` J.
2003-03-22 20:27 ` Anthony Nguyen
0 siblings, 1 reply; 10+ messages in thread
From: J. @ 2003-03-22 19:47 UTC (permalink / raw)
To: linux-c-programming
Hello,
struct {
char *name;
int telnr;
} people[100];
Instead of statically allocating an array of 100 of these structures like
I have done, I want to dynamically allocate the array at run-time and
resize the number of structures some where at any time in the main
program.
I know how to resize char arrays and int arrays but I never (re)sized an
array of structres which can be accessed with something as: ``people[4].name''.
In Google nothing really usefull turns up.
Can this be done without having to resort to other implementations like
linked lists etc.. ? If so how ?
Thank you in advance.
J.
^ permalink raw reply [flat|nested] 10+ messages in thread* RE: dynamic allocation of array of structures
2003-03-22 19:47 ` dynamic allocation of array of structures J.
@ 2003-03-22 20:27 ` Anthony Nguyen
2003-03-22 20:48 ` J.
0 siblings, 1 reply; 10+ messages in thread
From: Anthony Nguyen @ 2003-03-22 20:27 UTC (permalink / raw)
To: linux-c-programming
typedef struct Apeople {
char *name;
int telnr;
} Tpeople;
...
Tpeople *toto;
toto = (Tpeople *)(malloc (sizeof Tpeople) * <the number of elements you
want to allocate>);
But I think that you were searching a "proper way" to implement it, isn't it
:?
A.N.
-----Original Message-----
From: linux-c-programming-owner@vger.kernel.org
[mailto:linux-c-programming-owner@vger.kernel.org] On Behalf Of J.
Sent: Saturday, March 22, 2003 8:48 PM
To: linux-c-programming@vger.kernel.org
Hello,
struct {
char *name;
int telnr;
} people[100];
Instead of statically allocating an array of 100 of these structures like
I have done, I want to dynamically allocate the array at run-time and
resize the number of structures some where at any time in the main
program.
I know how to resize char arrays and int arrays but I never (re)sized an
array of structres which can be accessed with something as:
``people[4].name''.
In Google nothing really usefull turns up.
Can this be done without having to resort to other implementations like
linked lists etc.. ? If so how ?
Thank you in advance.
J.
-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 10+ messages in thread* RE: dynamic allocation of array of structures
2003-03-22 20:27 ` Anthony Nguyen
@ 2003-03-22 20:48 ` J.
2003-03-22 21:00 ` Elias Athanasopoulos
2003-03-22 21:44 ` dynamic allocation of array of structures, Thnkx J.
0 siblings, 2 replies; 10+ messages in thread
From: J. @ 2003-03-22 20:48 UTC (permalink / raw)
To: linux-c-programming
On Sat, 22 Mar 2003, Anthony Nguyen wrote:
> typedef struct Apeople {
> char *name;
> int telnr;
> } Tpeople;
>
> ...
>
> Tpeople *toto;
>
> toto = (Tpeople *)(malloc (sizeof Tpeople) * <the number of elements you
> want to allocate>);
>
> But I think that you were searching a "proper way" to implement it, isn't it
> :?
>
> A.N.
Lol :) euh ... to be honest .. actually yes ..
Of course before I decided to send a message to this list I have tried
something like you described above, but it doesn't work quitte as I
expected or better said, like I want it to work.
Maybe some of you could give a hunch what goes wrong.
(Code compiles without Complaining)
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char initial;
int roomnr;
} record;
int main(void) {
int i = 0;
record *ptr;
if((ptr = (record *)malloc(10 * sizeof(record))) == NULL) {
fprintf(stderr, "Error: failed malloc\n");
return 1;
}
for(i = 0; i < 10; i++, ptr++) {
ptr->initial = 'A' + i;
ptr->roomnr = i;
}
for(i = 0; i < 10; i++, ptr++) {
printf("ptr->initial = %c, ", ptr->initial);
printf("ptr->roomnr = %d\n", ptr->roomnr);
}
return 0;
}
Thnkx.. J.
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: dynamic allocation of array of structures
2003-03-22 20:48 ` J.
@ 2003-03-22 21:00 ` Elias Athanasopoulos
2003-03-22 21:28 ` Glynn Clements
2003-03-22 21:44 ` dynamic allocation of array of structures, Thnkx J.
1 sibling, 1 reply; 10+ messages in thread
From: Elias Athanasopoulos @ 2003-03-22 21:00 UTC (permalink / raw)
To: J.; +Cc: linux-c-programming
On Sat, Mar 22, 2003 at 09:48:12PM +0100, J. wrote:
> Maybe some of you could give a hunch what goes wrong.
You should use linked lists. The code below can work if you save
the starting offset of you elements, but in general it is not safe.
> #include <stdio.h>
> #include <stdlib.h>
>
> typedef struct {
> char initial;
> int roomnr;
> } record;
>
> int main(void) {
> int i = 0;
- record *ptr;
+ record *ptr, *t;
> if((ptr = (record *)malloc(10 * sizeof(record))) == NULL) {
> fprintf(stderr, "Error: failed malloc\n");
> return 1;
> }
+ t = ptr;
> for(i = 0; i < 10; i++, ptr++) {
> ptr->initial = 'A' + i;
> ptr->roomnr = i;
> }
+ ptr = t;
> for(i = 0; i < 10; i++, ptr++) {
> printf("ptr->initial = %c, ", ptr->initial);
> printf("ptr->roomnr = %d\n", ptr->roomnr);
> }
>
> return 0;
> }
Elias
--
University of Athens I bet the human brain
Physics Department is a kludge --Marvin Minsky
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: dynamic allocation of array of structures
2003-03-22 21:00 ` Elias Athanasopoulos
@ 2003-03-22 21:28 ` Glynn Clements
0 siblings, 0 replies; 10+ messages in thread
From: Glynn Clements @ 2003-03-22 21:28 UTC (permalink / raw)
To: linux-c-programming
J. wrote:
> struct {
> char *name;
> int telnr;
> } people[100];
>
> Instead of statically allocating an array of 100 of these structures like
> I have done, I want to dynamically allocate the array at run-time and
> resize the number of structures some where at any time in the main
> program.
>
> I know how to resize char arrays and int arrays but I never (re)sized an
> array of structres which can be accessed with something as: ``people[4].name''.
> In Google nothing really usefull turns up.
>
> Can this be done without having to resort to other implementations like
> linked lists etc.. ? If so how ?
Use malloc() and realloc(), i.e.
ptr = malloc(count * sizeof(record));
and:
ptr = realloc(ptr, count * sizeof(record));
Elias Athanasopoulos wrote:
> > Maybe some of you could give a hunch what goes wrong.
>
> You should use linked lists.
I can't see any reason to use linked lists here.
> The code below can work if you save
> the starting offset of you elements, but in general it is not safe.
[snip]
> + t = ptr;
>
> > for(i = 0; i < 10; i++, ptr++) {
> > ptr->initial = 'A' + i;
> > ptr->roomnr = i;
> > }
>
> + ptr = t;
It's better to just leave the original pointer alone, and work on the
copy, e.g.
for(i = 0, t = ptr; i < 10; i++, t++) {
t->initial = 'A' + i;
t->roomnr = i;
}
Actually, using explicit pointer increment operations for array
iteration is a throwback to the days before compilers commonly
performed loop induction optimisation.
Nowadays, you may as well just write:
for(i = 0; i < 10; i++) {
record *t = &ptr[i];
t->initial = 'A' + i;
t->roomnr = i;
}
Leave the induction up to the compiler; it's less likely to get it
wrong than a programmer is.
--
Glynn Clements <glynn.clements@virgin.net>
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: dynamic allocation of array of structures, Thnkx..
2003-03-22 20:48 ` J.
2003-03-22 21:00 ` Elias Athanasopoulos
@ 2003-03-22 21:44 ` J.
1 sibling, 0 replies; 10+ messages in thread
From: J. @ 2003-03-22 21:44 UTC (permalink / raw)
To: linux-c-programming
I got the picture and everything works fine now.
I learned something again...
Merci.
J.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2003-03-22 21:44 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-28 3:26 ODBC Under Linux chuckw
2003-02-28 21:31 ` Glynn Clements
2003-03-19 13:22 ` How to open a file and to disable other processes from removing it Alexi Jordanov
2003-03-19 15:45 ` Glynn Clements
2003-03-22 19:47 ` dynamic allocation of array of structures J.
2003-03-22 20:27 ` Anthony Nguyen
2003-03-22 20:48 ` J.
2003-03-22 21:00 ` Elias Athanasopoulos
2003-03-22 21:28 ` Glynn Clements
2003-03-22 21:44 ` dynamic allocation of array of structures, Thnkx J.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).