Skip to content

Commit

Permalink
ex.c: buffer content of the oldest used buffer gets replaced if all b…
Browse files Browse the repository at this point in the history
…uffers are used
  • Loading branch information
cjwagenius committed Nov 19, 2020
1 parent ab9d342 commit 4307476
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ex.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ static struct buf {
long mtime; /* modification time */
} bufs[8];

static int bufs_cnt = 0; /* number of allocated buffers */

static int bufs_find(char *path)
{
int i;
Expand All @@ -52,7 +50,6 @@ static void bufs_free(int idx)
if (bufs[idx].lb) {
free(bufs[idx].path);
lbuf_free(bufs[idx].lb);
memset(&bufs[idx], 0, sizeof(bufs[idx]));
}
}

Expand All @@ -70,8 +67,9 @@ static int bufs_open(char *path)
for (i = 0; i < LEN(bufs) - 1; i++)
if (!bufs[i].lb)
break;
if (!bufs[i].lb)
bufs[i].id = i + 1;
bufs_free(i);
bufs[i].id = ++bufs_cnt;
bufs[i].path = uc_dup(path);
bufs[i].lb = lbuf_make();
bufs[i].row = 0;
Expand Down

0 comments on commit 4307476

Please sign in to comment.